Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qv4runtime.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qv4runtime_p.h"
5
6#include <private/qqmlengine_p.h>
7#include <private/qqmljavascriptexpression_p.h>
8#include <private/qqmljsast_p.h>
9#include <private/qqmltypewrapper_p.h>
10#include <private/qqmlvaluetypewrapper_p.h>
11#include <private/qv4argumentsobject_p.h>
12#include <private/qv4engine_p.h>
13#include <private/qv4function_p.h>
14#include <private/qv4generatorobject_p.h>
15#include <private/qv4global_p.h>
16#include <private/qv4globalobject_p.h>
17#include <private/qv4jscall_p.h>
18#include <private/qv4lookup_p.h>
19#include <private/qv4math_p.h>
20#include <private/qv4object_p.h>
21#include <private/qv4qmlcontext_p.h>
22#include <private/qv4qobjectwrapper_p.h>
23#include <private/qv4regexp_p.h>
24#include <private/qv4regexpobject_p.h>
25#include <private/qv4scopedvalue_p.h>
26#include <private/qv4stackframe_p.h>
27#include <private/qv4symbol_p.h>
28
29#include <wtf/MathExtras.h>
30
31#include <QtCore/private/qlocale_tools_p.h>
32#include <QtCore/qdebug.h>
33
34#ifdef QV4_COUNT_RUNTIME_FUNCTIONS
35# include <QtCore/qbuffer.h>
36#endif // QV4_COUNT_RUNTIME_FUNCTIONS
37
38#include <cassert>
39#include <cstdio>
40#include <stdlib.h>
41
43
44namespace QV4 {
45
46#ifdef QV4_COUNT_RUNTIME_FUNCTIONS
47struct RuntimeCounters::Data {
48 enum Type {
49 None = 0,
50 Undefined = 1,
51 Null = 2,
52 Boolean = 3,
53 Integer = 4,
54 Managed = 5,
55 Double = 7
56 };
57
58 static const char *pretty(Type t) {
59 switch (t) {
60 case None: return "";
61 case Undefined: return "Undefined";
62 case Null: return "Null";
63 case Boolean: return "Boolean";
64 case Integer: return "Integer";
65 case Managed: return "Managed";
66 case Double: return "Double";
67 default: return "Unknown";
68 }
69 }
70
71 static unsigned mangle(unsigned tag) {
72 switch (tag) {
73 case Value::Undefined_Type: return Undefined;
74 case Value::Null_Type: return Null;
75 case Value::Boolean_Type: return Boolean;
76 case Value::Integer_Type: return Integer;
77 case Value::Managed_Type: return Managed;
78 default: return Double;
79 }
80 }
81
82 static unsigned mangle(unsigned tag1, unsigned tag2) {
83 return (mangle(tag1) << 3) | mangle(tag2);
84 }
85
86 static void unmangle(unsigned signature, Type &tag1, Type &tag2) {
87 tag1 = Type((signature >> 3) & 7);
88 tag2 = Type(signature & 7);
89 }
90
91 typedef QVector<quint64> Counters;
93
94 inline void count(const char *func) {
96 if (cnt.isEmpty())
97 cnt.resize(64);
98 cnt[0] += 1;
99 }
100
101 inline void count(const char *func, unsigned tag) {
103 if (cnt.isEmpty())
104 cnt.resize(64);
105 cnt[mangle(tag)] += 1;
106 }
107
108 inline void count(const char *func, unsigned tag1, unsigned tag2) {
110 if (cnt.isEmpty())
111 cnt.resize(64);
112 cnt[mangle(tag1, tag2)] += 1;
113 }
114
115 struct Line {
116 const char *func;
117 Type tag1, tag2;
119
120 static bool less(const Line &line1, const Line &line2) {
121 return line1.count > line2.count;
122 }
123 };
124
125 void dump() const {
126 QBuffer buf;
128 QTextStream outs(&buf);
129 QList<Line> lines;
130 for (auto it = counters.cbegin(), end = counters.cend(); it != end; ++it) {
131 const Counters &fCount = it.value();
132 for (int i = 0, ei = fCount.size(); i != ei; ++i) {
133 quint64 count = fCount[i];
134 if (!count)
135 continue;
136 Line line;
137 line.func = it.key();
138 unmangle(i, line.tag1, line.tag2);
139 line.count = count;
140 lines.append(line);
141 }
142 }
143 std::sort(lines.begin(), lines.end(), Line::less);
144 outs << lines.size() << " counters:" << endl;
145 for (const Line &line : std::as_const(lines))
146 outs << qSetFieldWidth(10) << line.count << qSetFieldWidth(0)
147 << " | " << line.func
148 << " | " << pretty(line.tag1)
149 << " | " << pretty(line.tag2)
150 << endl;
151 qDebug("%s", buf.data().constData());
152 }
153};
154
155RuntimeCounters *RuntimeCounters::instance = 0;
156static RuntimeCounters runtimeCountersInstance;
157RuntimeCounters::RuntimeCounters()
158 : d(new Data)
159{
160 if (!instance)
161 instance = this;
162}
163
164RuntimeCounters::~RuntimeCounters()
165{
166 d->dump();
167 delete d;
168}
169
170void RuntimeCounters::count(const char *func)
171{
172 d->count(func);
173}
174
175void RuntimeCounters::count(const char *func, uint tag)
176{
177 d->count(func, tag);
178}
179
180void RuntimeCounters::count(const char *func, uint tag1, uint tag2)
181{
182 d->count(func, tag1, tag2);
183}
184
185#endif // QV4_COUNT_RUNTIME_FUNCTIONS
186
188{
189 return f->executableCompilationUnit()->runtimeLookups + i;
190}
191
192void RuntimeHelpers::numberToString(QString *result, double num, int radix)
193{
195
196 if (std::isnan(num)) {
197 *result = QStringLiteral("NaN");
198 return;
199 } else if (qt_is_inf(num)) {
200 *result = num < 0 ? QStringLiteral("-Infinity") : QStringLiteral("Infinity");
201 return;
202 }
203
204 if (radix == 10) {
205 // We cannot use our usual locale->toString(...) here, because EcmaScript has special rules
206 // about the longest permissible number, depending on if it's <0 or >0.
207 const int ecma_shortest_low = -6;
208 const int ecma_shortest_high = 21;
209
210 const QLatin1Char zero('0');
211 const QLatin1Char dot('.');
212
213 int decpt = 0;
214 int sign = 0;
215 *result = qdtoa(num, &decpt, &sign);
216
217 if (decpt <= ecma_shortest_low || decpt > ecma_shortest_high) {
218 if (result->size() > 1)
219 result->insert(1, dot);
220 result->append(QLatin1Char('e'));
221 if (decpt > 0)
222 result->append(QLatin1Char('+'));
223 result->append(QString::number(decpt - 1));
224 } else if (decpt <= 0) {
225 result->prepend(QLatin1String("0.") + QString(-decpt, zero));
226 } else if (decpt < result->size()) {
227 result->insert(decpt, dot);
228 } else {
229 result->append(QString(decpt - result->size(), zero));
230 }
231
232 if (sign && num)
233 result->prepend(QLatin1Char('-'));
234
235 return;
236 }
237
238 result->clear();
239 bool negative = false;
240
241 if (num < 0) {
242 negative = true;
243 num = -num;
244 }
245
246 double frac = num - ::floor(num);
247 num = Value::toInteger(num);
248
249 do {
250 char c = (char)::fmod(num, radix);
251 c = (c < 10) ? (c + '0') : (c - 10 + 'a');
252 result->prepend(QLatin1Char(c));
253 num = ::floor(num / radix);
254 } while (num != 0);
255
256 if (frac != 0) {
257 result->append(QLatin1Char('.'));
258 double magnitude = 1;
259 double next = frac;
260 do {
261 next *= radix;
262 const int floored = ::floor(next);
263 char c = char(floored);
264 c = (c < 10) ? (c + '0') : (c - 10 + 'a');
265 result->append(QLatin1Char(c));
266 magnitude /= radix;
267 frac -= double(floored) * magnitude;
268 next -= double(floored);
269
270 // The next digit still makes a difference
271 // if a value of "radix" for it would change frac.
272 // Otherwise we've reached the limit of numerical precision.
273 } while (frac > 0 && frac - magnitude != frac);
274 }
275
276 if (negative)
277 result->prepend(QLatin1Char('-'));
278}
279
280ReturnedValue Runtime::Closure::call(ExecutionEngine *engine, int functionId)
281{
282 QV4::Function *clos = engine->currentStackFrame->v4Function->executableCompilationUnit()
283 ->runtimeFunctions[functionId];
284 Q_ASSERT(clos);
285 ExecutionContext *current = engine->currentContext();
286 if (clos->isGenerator())
287 return GeneratorFunction::create(current, clos)->asReturnedValue();
288 return FunctionObject::createScriptFunction(current, clos)->asReturnedValue();
289}
290
291Bool Runtime::DeleteProperty_NoThrow::call(ExecutionEngine *engine, const Value &base, const Value &index)
292{
293 Scope scope(engine);
294 ScopedObject o(scope, base.toObject(engine));
295 if (scope.hasException())
296 return Encode::undefined();
297 Q_ASSERT(o);
298
299 ScopedPropertyKey key(scope, index.toPropertyKey(engine));
300 if (engine->hasException)
301 return false;
302 return o->deleteProperty(key);
303}
304
305ReturnedValue Runtime::DeleteProperty::call(ExecutionEngine *engine, QV4::Function *function, const QV4::Value &base, const QV4::Value &index)
306{
307 if (!Runtime::DeleteProperty_NoThrow::call(engine, base, index)) {
308 if (function->isStrict())
309 engine->throwTypeError();
310 return Encode(false);
311 } else {
312 return Encode(true);
313 }
314}
315
316Bool Runtime::DeleteName_NoThrow::call(ExecutionEngine *engine, int nameIndex)
317{
318 Scope scope(engine);
319 ScopedString name(scope, engine->currentStackFrame->v4Function->compilationUnit->runtimeStrings[nameIndex]);
320 return engine->currentContext()->deleteProperty(name);
321}
322
323ReturnedValue Runtime::DeleteName::call(ExecutionEngine *engine, Function *function, int name)
324{
325 if (!Runtime::DeleteName_NoThrow::call(engine, name)) {
326 if (function->isStrict())
327 engine->throwTypeError();
328 return Encode(false);
329 } else {
330 return Encode(true);
331 }
332}
333
335{
336 // 11.8.6, 5: rval must be an Object
337 const Object *rhs = rval.as<Object>();
338 if (!rhs)
339 return engine->throwTypeError();
340
341 const FunctionObject *f = rhs->as<FunctionObject>();
342 // shortcut hasInstance evaluation. In this case we know that we are calling the regular hasInstance()
343 // method of the FunctionPrototype
344 if (f && f->d()->prototype() == engine->functionPrototype()->d() && !f->hasHasInstanceProperty())
345 return Object::checkedInstanceOf(engine, f, lval);
346
347 Scope scope(engine);
348 ScopedValue hasInstance(scope, rhs->get(engine->symbol_hasInstance()));
349 if (hasInstance->isUndefined())
350 return Encode(rhs->instanceOf(lval));
351
352 FunctionObject *fHasInstance = hasInstance->as<FunctionObject>();
353 if (!fHasInstance)
354 return engine->throwTypeError();
355
356 return Encode(fHasInstance->call(&rval, &lval, 1));
357}
358
359QV4::ReturnedValue Runtime::Instanceof::call(ExecutionEngine *engine, const Value &lval, const Value &rval)
360{
361 Scope scope(engine);
362 ScopedValue result(scope, doInstanceof(engine, lval, rval));
363 return scope.hasException() ? Encode::undefined() : Encode(result->toBoolean());
364}
365
366QV4::ReturnedValue Runtime::As::call(ExecutionEngine *engine, const Value &lval, const Value &rval)
367{
368 Scope scope(engine);
369 ScopedValue result(scope, doInstanceof(engine, lval, rval));
370
371 if (scope.hasException()) {
372 // "foo instanceof valueType" must not throw an exception.
373 // So this can only be an object type.
374 engine->catchException();
375 return Encode::null();
376 }
377
378 if (result->toBoolean())
379 return lval.asReturnedValue();
380 else if (result->isBoolean())
381 return Encode::null();
382
383 // Try to convert the value type
384 if (Scoped<QQmlTypeWrapper> typeWrapper(scope, rval); typeWrapper)
385 return coerce(engine, lval, typeWrapper->d()->type(), false);
386
387 return Encode::undefined();
388}
389
390QV4::ReturnedValue Runtime::In::call(ExecutionEngine *engine, const Value &left, const Value &right)
391{
392 Object *ro = right.objectValue();
393 if (!ro)
394 return engine->throwTypeError();
395 Scope scope(engine);
396 ScopedPropertyKey s(scope, left.toPropertyKey(engine));
397 if (scope.hasException())
398 return Encode::undefined();
399 bool r = ro->hasProperty(s);
400 return Encode(r);
401}
402
403double RuntimeHelpers::stringToNumber(const QString &string)
404{
405 // The actual maximum valid length is certainly shorter, but due to the sheer number of
406 // different number formatting variants, we rather err on the side of caution here.
407 // For example, you can have up to 772 valid decimal digits left of the dot, as stated in the
408 // libdoubleconversion sources. The same maximum value would be represented by roughly 3.5 times
409 // as many binary digits.
410 const int excessiveLength = 16 * 1024;
411 if (string.size() > excessiveLength)
412 return qQNaN();
413
414 const QStringView s = QStringView(string).trimmed();
415 if (s.startsWith(QLatin1Char('0'))) {
416 int base = -1;
417 if (s.startsWith(QLatin1String("0x")) || s.startsWith(QLatin1String("0X")))
418 base = 16;
419 else if (s.startsWith(QLatin1String("0o")) || s.startsWith(QLatin1String("0O")))
420 base = 8;
421 else if (s.startsWith(QLatin1String("0b")) || s.startsWith(QLatin1String("0B")))
422 base = 2;
423 if (base > 0) {
424 bool ok = true;
426 num = s.mid(2).toLongLong(&ok, base);
427 if (!ok)
428 return qQNaN();
429 return num;
430 }
431 }
432 bool ok = false;
433 QByteArray ba = s.toLatin1();
434 const char *begin = ba.constData();
435 const char *end = nullptr;
436 double d = qstrtod(begin, &end, &ok);
437 if (end - begin != ba.size()) {
438 if (ba == "Infinity" || ba == "+Infinity")
439 d = Q_INFINITY;
440 else if (ba == "-Infinity")
441 d = -Q_INFINITY;
442 else
443 d = std::numeric_limits<double>::quiet_NaN();
444 }
445 return d;
446}
447
448Heap::String *RuntimeHelpers::stringFromNumber(ExecutionEngine *engine, double number)
449{
450 QString qstr;
451 RuntimeHelpers::numberToString(&qstr, number, 10);
452 return engine->newString(qstr);
453}
454
455ReturnedValue RuntimeHelpers::objectDefaultValue(const Object *object, int typeHint)
456{
457 ExecutionEngine *engine = object->internalClass()->engine;
458 if (engine->hasException)
459 return Encode::undefined();
460
461 String *hint;
462 switch (typeHint) {
463 case STRING_HINT:
464 hint = engine->id_string();
465 break;
466 case NUMBER_HINT:
467 hint = engine->id_number();
468 break;
469 default:
470 hint = engine->id_default();
471 break;
472 }
473
474 Scope scope(engine);
475 ScopedFunctionObject toPrimitive(scope, object->get(engine->symbol_toPrimitive()));
476 if (engine->hasException)
477 return Encode::undefined();
478 if (toPrimitive) {
479 ScopedValue result(scope, toPrimitive->call(object, hint, 1));
480 if (engine->hasException)
481 return Encode::undefined();
482 if (!result->isPrimitive())
483 return engine->throwTypeError();
484 return result->asReturnedValue();
485 }
486
487 if (hint == engine->id_default())
488 hint = engine->id_number();
489 return ordinaryToPrimitive(engine, object, hint);
490}
491
492
493ReturnedValue RuntimeHelpers::ordinaryToPrimitive(ExecutionEngine *engine, const Object *object, String *typeHint)
494{
495 Q_ASSERT(!engine->hasException);
496
497 String *meth1 = engine->id_toString();
498 String *meth2 = engine->id_valueOf();
499
500 if (typeHint->propertyKey() == engine->id_number()->propertyKey()) {
501 qSwap(meth1, meth2);
502 } else {
503 Q_ASSERT(typeHint->propertyKey() == engine->id_string()->propertyKey());
504 }
505
506 Scope scope(engine);
507 ScopedValue result(scope);
508
509 ScopedValue conv(scope, object->get(meth1));
510 if (FunctionObject *o = conv->as<FunctionObject>()) {
511 result = o->call(object, nullptr, 0);
512 if (engine->hasException)
513 return Encode::undefined();
514 if (result->isPrimitive())
515 return result->asReturnedValue();
516 }
517
518 if (engine->hasException)
519 return Encode::undefined();
520
521 conv = object->get(meth2);
522 if (FunctionObject *o = conv->as<FunctionObject>()) {
523 result = o->call(object, nullptr, 0);
524 if (engine->hasException)
525 return Encode::undefined();
526 if (result->isPrimitive())
527 return result->asReturnedValue();
528 }
529
530 return engine->throwTypeError();
531}
532
533
534Heap::Object *RuntimeHelpers::convertToObject(ExecutionEngine *engine, const Value &value)
535{
536 Q_ASSERT(!value.isObject());
537 switch (value.type()) {
538 case Value::Undefined_Type:
539 engine->throwTypeError(QLatin1String("Value is undefined and could not be converted to an object"));
540 return nullptr;
541 case Value::Null_Type:
542 engine->throwTypeError(QLatin1String("Value is null and could not be converted to an object"));
543 return nullptr;
544 case Value::Boolean_Type:
545 return engine->newBooleanObject(value.booleanValue());
546 case Value::Managed_Type:
547 Q_ASSERT(value.isStringOrSymbol());
548 if (!value.isString())
549 return engine->newSymbolObject(value.symbolValue());
550 return engine->newStringObject(value.stringValue());
551 case Value::Integer_Type:
552 default: // double
553 return engine->newNumberObject(value.asDouble());
554 }
555}
556
557Heap::String *RuntimeHelpers::convertToString(ExecutionEngine *engine, Value value, TypeHint hint)
558{
559 redo:
560 switch (value.type()) {
561 case Value::Empty_Type:
562 Q_ASSERT(!"empty Value encountered");
563 Q_UNREACHABLE();
564 case Value::Undefined_Type:
565 return engine->id_undefined()->d();
566 case Value::Null_Type:
567 return engine->id_null()->d();
568 case Value::Boolean_Type:
569 if (value.booleanValue())
570 return engine->id_true()->d();
571 else
572 return engine->id_false()->d();
573 case Value::Managed_Type: {
574 if (value.isString())
575 return static_cast<const String &>(value).d();
576 if (value.isSymbol()) {
577 engine->throwTypeError(QLatin1String("Cannot convert a symbol to a string."));
578 return nullptr;
579 }
580 value = Value::fromReturnedValue(RuntimeHelpers::toPrimitive(value, hint));
581 Q_ASSERT(value.isPrimitive());
582 if (value.isString())
583 return static_cast<const String &>(value).d();
584 goto redo;
585 }
586 case Value::Integer_Type:
587 return RuntimeHelpers::stringFromNumber(engine, value.int_32());
588 default: // double
589 return RuntimeHelpers::stringFromNumber(engine, value.doubleValue());
590 } // switch
591}
592
593// This is slightly different from the method above, as
594// the + operator requires a slightly different conversion
596{
597 return RuntimeHelpers::convertToString(engine, value, PREFERREDTYPE_HINT);
598}
599
600QV4::ReturnedValue RuntimeHelpers::addHelper(ExecutionEngine *engine, const Value &left, const Value &right)
601{
602 Scope scope(engine);
603
604 ScopedValue pleft(scope, RuntimeHelpers::toPrimitive(left, PREFERREDTYPE_HINT));
605 ScopedValue pright(scope, RuntimeHelpers::toPrimitive(right, PREFERREDTYPE_HINT));
606 String *sleft = pleft->stringValue();
607 String *sright = pright->stringValue();
608 if (sleft || sright) {
609 if (!sleft) {
610 pleft = convert_to_string_add(engine, pleft);
611 sleft = static_cast<String *>(pleft.ptr);
612 }
613 if (!sright) {
614 pright = convert_to_string_add(engine, pright);
615 sright = static_cast<String *>(pright.ptr);
616 }
617 if (engine->hasException)
618 return Encode::undefined();
619 if (!sleft->d()->length())
620 return sright->asReturnedValue();
621 if (!sright->d()->length())
622 return sleft->asReturnedValue();
623 MemoryManager *mm = engine->memoryManager;
624 return (mm->alloc<ComplexString>(sleft->d(), sright->d()))->asReturnedValue();
625 }
626 double x = RuntimeHelpers::toNumber(pleft);
627 double y = RuntimeHelpers::toNumber(pright);
628 return Encode(x + y);
629}
630
631ReturnedValue Runtime::GetTemplateObject::call(Function *function, int index)
632{
633 return function->executableCompilationUnit()->templateObjectAt(index)->asReturnedValue();
634}
635
636void Runtime::StoreProperty::call(ExecutionEngine *engine, const Value &object, int nameIndex, const Value &value)
637{
638 Scope scope(engine);
639 QV4::Function *v4Function = engine->currentStackFrame->v4Function;
640 ScopedString name(scope, v4Function->compilationUnit->runtimeStrings[nameIndex]);
641 ScopedObject o(scope, object);
642 if (!o) {
643 if (v4Function->isStrict()) {
644 engine->throwTypeError();
645 return;
646 }
647 o = object.toObject(engine);
648 }
649 if ((!o || !o->put(name, value)) && v4Function->isStrict())
650 engine->throwTypeError();
651}
652
654{
655 Q_ASSERT(idx < UINT_MAX);
656 Scope scope(engine);
657
658 ScopedObject o(scope, object);
659 if (!o) {
660 if (const String *str = object.as<String>()) {
661 if (idx >= (uint)str->toQString().size()) {
662 return Encode::undefined();
663 }
664 const QString s = str->toQString().mid(idx, 1);
665 return scope.engine->newString(s)->asReturnedValue();
666 }
667
668 if (object.isNullOrUndefined()) {
669 QString message = QStringLiteral("Cannot read property '%1' of %2").arg(idx).arg(object.toQStringNoThrow());
670 return engine->throwTypeError(message);
671 }
672
673 o = RuntimeHelpers::convertToObject(scope.engine, object);
674 Q_ASSERT(!!o); // can't fail as null/undefined is covered above
675 }
676
677 if (o->arrayData() && !o->arrayData()->attrs) {
678 ScopedValue v(scope, o->arrayData()->get(idx));
679 if (!v->isEmpty())
680 return v->asReturnedValue();
681 }
682
683 return o->get(idx);
684}
685
687{
688 Q_ASSERT(!index.isPositiveInt());
689
690 Scope scope(engine);
691
692 ScopedObject o(scope, object);
693 if (!o) {
694 if (object.isNullOrUndefined()) {
695 QString message = QStringLiteral("Cannot read property '%1' of %2").arg(index.toQStringNoThrow()).arg(object.toQStringNoThrow());
696 return engine->throwTypeError(message);
697 }
698
699 o = RuntimeHelpers::convertToObject(scope.engine, object);
700 Q_ASSERT(!!o); // can't fail as null/undefined is covered above
701 }
702
703 ScopedPropertyKey name(scope, index.toPropertyKey(engine));
704 if (scope.hasException())
705 return Encode::undefined();
706 return o->get(name);
707}
708
709ReturnedValue Runtime::LoadElement::call(ExecutionEngine *engine, const Value &object, const Value &index)
710{
711 if (index.isPositiveInt()) {
712 uint idx = static_cast<uint>(index.int_32());
713 if (Heap::Base *b = object.heapObject()) {
714 if (b->internalClass->vtable->isObject) {
715 Heap::Object *o = static_cast<Heap::Object *>(b);
716 if (o->arrayData && o->arrayData->type == Heap::ArrayData::Simple) {
717 Heap::SimpleArrayData *s = o->arrayData.cast<Heap::SimpleArrayData>();
718 if (idx < s->values.size)
719 if (!s->data(idx).isEmpty())
720 return s->data(idx).asReturnedValue();
721 }
722 }
723 }
724 return getElementIntFallback(engine, object, idx);
725 }
726
727 return getElementFallback(engine, object, index);
728}
729
731{
732 Scope scope(engine);
733 ScopedObject o(scope, object);
734 if (!o) {
735 if (engine->currentStackFrame->v4Function->isStrict()) {
736 engine->throwTypeError();
737 return false;
738 }
739
740 o = object.toObject(engine);
741 }
742 if (engine->hasException)
743 return false;
744
745 if (index.isPositiveInt()) {
746 uint idx = static_cast<uint>(index.int_32());
747 if (o->d()->arrayData && o->d()->arrayData->type == Heap::ArrayData::Simple) {
748 Heap::SimpleArrayData *s = o->d()->arrayData.cast<Heap::SimpleArrayData>();
749 if (idx < s->values.size) {
750 s->setData(engine, idx, value);
751 return true;
752 }
753 }
754 return o->put(idx, value);
755 }
756
757 ScopedPropertyKey name(scope, index.toPropertyKey(engine));
758 if (engine->hasException)
759 return false;
760 return o->put(name, value);
761}
762
763void Runtime::StoreElement::call(ExecutionEngine *engine, const Value &object, const Value &index, const Value &value)
764{
765 if (index.isPositiveInt()) {
766 uint idx = static_cast<uint>(index.int_32());
767 if (Heap::Base *b = object.heapObject()) {
768 if (b->internalClass->vtable->isObject) {
769 Heap::Object *o = static_cast<Heap::Object *>(b);
770 if (o->arrayData && o->arrayData->type == Heap::ArrayData::Simple) {
771 Heap::SimpleArrayData *s = o->arrayData.cast<Heap::SimpleArrayData>();
772 if (idx < s->values.size) {
773 s->setData(engine, idx, value);
774 return;
775 }
776 }
777 }
778 }
779 }
780
781 if (!setElementFallback(engine, object, index, value) && engine->currentStackFrame->v4Function->isStrict())
782 engine->throwTypeError();
783}
784
785ReturnedValue Runtime::GetIterator::call(ExecutionEngine *engine, const Value &in, int iterator)
786{
787 Scope scope(engine);
788 ScopedObject o(scope, (Object *)nullptr);
789 if (!in.isNullOrUndefined())
790 o = in.toObject(engine);
791 if (engine->hasException)
792 return Encode::undefined();
793 if (iterator == static_cast<int>(QQmlJS::AST::ForEachType::Of)) {
794 if (!o)
795 return engine->throwTypeError();
796 ScopedFunctionObject f(scope, o->get(engine->symbol_iterator()));
797 if (!f)
798 return engine->throwTypeError();
799 JSCallData cData(o, nullptr, 0);
800 ScopedObject it(scope, f->call(cData));
801 if (engine->hasException)
802 return Encode::undefined();
803 if (!it)
804 return engine->throwTypeError();
805 return it->asReturnedValue();
806 }
807 return engine->newForInIteratorObject(o)->asReturnedValue();
808}
809
810ReturnedValue Runtime::IteratorNext::call(ExecutionEngine *engine, const Value &iterator, Value *value)
811{
812 // if we throw an exception from here, return true, not undefined. This is to ensure iteratorDone is set to true
813 // and the stack unwinding won't close the iterator
814 Q_ASSERT(iterator.isObject());
815
816 Scope scope(engine);
817 ScopedFunctionObject f(scope, static_cast<const Object &>(iterator).get(engine->id_next()));
818 if (!f) {
819 engine->throwTypeError();
820 return Encode(true);
821 }
822 JSCallData cData(&iterator, nullptr, 0);
823 ScopedObject o(scope, f->call(cData));
824 if (scope.hasException())
825 return Encode(true);
826 if (!o) {
827 engine->throwTypeError();
828 return Encode(true);
829 }
830
831 ScopedValue d(scope, o->get(engine->id_done()));
832 if (scope.hasException())
833 return Encode(true);
834 bool done = d->toBoolean();
835 if (done) {
836 *value = Encode::undefined();
837 return Encode(true);
838 }
839
840 *value = o->get(engine->id_value());
841 if (scope.hasException())
842 return Encode(true);
843 return Encode(false);
844}
845
846ReturnedValue Runtime::IteratorNextForYieldStar::call(ExecutionEngine *engine, const Value &received, const Value &iterator, Value *object)
847{
848 // the return value encodes how to continue the yield* iteration.
849 // true implies iteration is done, false for iteration to continue
850 // a return value of undefines is a special marker, that the iterator has been invoked with return()
851
852 Scope scope(engine);
853 Q_ASSERT(iterator.isObject());
854
855 const Value *arg = &received;
856 bool returnCalled = false;
857 FunctionObject *f = nullptr;
858 if (engine->hasException) {
859 if (engine->exceptionValue->isEmpty()) {
860 // generator called with return()
861 *engine->exceptionValue = Encode::undefined();
862 engine->hasException = false;
863
864 ScopedValue ret(scope, static_cast<const Object &>(iterator).get(engine->id_return()));
865 if (ret->isUndefined()) {
866 // propagate return()
867 return Encode::undefined();
868 }
869 returnCalled = true;
870 f = ret->as<FunctionObject>();
871 } else {
872 // generator called with throw
873 ScopedValue exceptionValue(scope, *engine->exceptionValue);
874 *engine->exceptionValue = Encode::undefined();
875 engine->hasException = false;
876
877 ScopedValue t(scope, static_cast<const Object &>(iterator).get(engine->id_throw()));
878 if (engine->hasException)
879 return Encode::undefined();
880 if (t->isUndefined()) {
881 // no throw method on the iterator
882 ScopedValue done(scope, Encode(false));
883 IteratorClose::call(engine, iterator, done);
884 if (engine->hasException)
885 return Encode::undefined();
886 return engine->throwTypeError();
887 }
888 f = t->as<FunctionObject>();
889 arg = exceptionValue;
890 }
891 } else {
892 // generator called with next()
893 ScopedFunctionObject next(scope, static_cast<const Object &>(iterator).get(engine->id_next()));
894 f = next->as<FunctionObject>();
895 }
896
897 if (!f)
898 return engine->throwTypeError();
899
900 ScopedObject o(scope, f->call(&iterator, arg, 1));
901 if (scope.hasException())
902 return Encode(true);
903 if (!o)
904 return engine->throwTypeError();
905
906 ScopedValue d(scope, o->get(engine->id_done()));
907 if (scope.hasException())
908 return Encode(true);
909 bool done = d->toBoolean();
910 if (done) {
911 *object = o->get(engine->id_value());
912 return returnCalled ? Encode::undefined() : Encode(true);
913 }
914 *object = o;
915 return Encode(false);
916}
917
918ReturnedValue Runtime::IteratorClose::call(ExecutionEngine *engine, const Value &iterator, const Value &done)
919{
920 Q_ASSERT(iterator.isObject());
921 Q_ASSERT(done.isBoolean());
922 if (done.booleanValue())
923 return Encode::undefined();
924
925 Scope scope(engine);
926 ScopedValue e(scope);
927 bool hadException = engine->hasException;
928 if (hadException) {
929 e = *engine->exceptionValue;
930 engine->hasException = false;
931 }
932
933 auto originalCompletion = [=]() {
934 if (hadException) {
935 *engine->exceptionValue = e;
936 engine->hasException = hadException;
937 }
938 return Encode::undefined();
939 };
940
941 ScopedValue ret(scope, static_cast<const Object &>(iterator).get(engine->id_return()));
942 ScopedObject o(scope);
943 if (!ret->isUndefined()) {
945 o = f->call(&iterator, nullptr, 0);
946 if (engine->hasException && !hadException)
947 return Encode::undefined();
948 }
949 if (hadException || ret->isUndefined())
950 return originalCompletion();
951
952 if (!o)
953 return engine->throwTypeError();
954
955 return originalCompletion();
956}
957
958ReturnedValue Runtime::DestructureRestElement::call(ExecutionEngine *engine, const Value &iterator)
959{
960 Q_ASSERT(iterator.isObject());
961
962 Scope scope(engine);
963 ScopedArrayObject array(scope, engine->newArrayObject());
964 array->arrayCreate();
965 uint index = 0;
966 while (1) {
967 ScopedValue n(scope);
968 ScopedValue done(scope, IteratorNext::call(engine, iterator, n));
969 if (engine->hasException)
970 return Encode::undefined();
971 Q_ASSERT(done->isBoolean());
972 if (done->booleanValue())
973 break;
974 array->arraySet(index, n);
975 ++index;
976 }
977 return array->asReturnedValue();
978}
979
980void Runtime::StoreNameSloppy::call(ExecutionEngine *engine, int nameIndex, const Value &value)
981{
982 Scope scope(engine);
983 ScopedString name(scope, engine->currentStackFrame->v4Function->compilationUnit->runtimeStrings[nameIndex]);
984 ExecutionContext::Error e = engine->currentContext()->setProperty(name, value);
985
986 if (e == ExecutionContext::RangeError)
988}
989
990void Runtime::StoreNameStrict::call(ExecutionEngine *engine, int nameIndex, const Value &value)
991{
992 Scope scope(engine);
993 ScopedString name(scope, engine->currentStackFrame->v4Function->compilationUnit->runtimeStrings[nameIndex]);
994 ExecutionContext::Error e = engine->currentContext()->setProperty(name, value);
995 if (e == ExecutionContext::TypeError)
996 engine->throwTypeError();
997 else if (e == ExecutionContext::RangeError)
998 engine->throwReferenceError(name);
999}
1000
1001ReturnedValue Runtime::LoadProperty::call(ExecutionEngine *engine, const Value &object, int nameIndex)
1002{
1003 Scope scope(engine);
1004 ScopedString name(scope, engine->currentStackFrame->v4Function->compilationUnit->runtimeStrings[nameIndex]);
1005
1006 ScopedObject o(scope, object);
1007 if (o)
1008 return o->get(name);
1009
1010 if (object.isNullOrUndefined()) {
1011 QString message = QStringLiteral("Cannot read property '%1' of %2").arg(name->toQString()).arg(object.toQStringNoThrow());
1012 return engine->throwTypeError(message);
1013 }
1014
1015 o = RuntimeHelpers::convertToObject(scope.engine, object);
1016 if (!o) // type error
1017 return Encode::undefined();
1018 return o->get(name);
1019}
1020
1021ReturnedValue Runtime::LoadName::call(ExecutionEngine *engine, int nameIndex)
1022{
1023 Scope scope(engine);
1024 ScopedString name(scope, engine->currentStackFrame->v4Function->compilationUnit->runtimeStrings[nameIndex]);
1025 return engine->currentContext()->getProperty(name);
1026}
1027
1029{
1030 ScopedFunctionObject f(scope);
1031 ScopedObject homeObject(scope);
1032 if (scope.engine->currentStackFrame->isJSTypesFrame()) {
1033 JSTypesStackFrame *frame = static_cast<JSTypesStackFrame *>(
1034 scope.engine->currentStackFrame);
1035
1036 if (frame->jsFrame->thisObject.isEmpty()) {
1038 QStringLiteral("Missing call to super()."), QString(), 0, 0);
1039 return nullptr;
1040 }
1041
1042 f = Value::fromStaticValue(frame->jsFrame->function);
1043 homeObject = f->getHomeObject();
1044 } else {
1047 scope.engine->currentStackFrame);
1048 if (frame->thisObject() == nullptr) {
1050 QStringLiteral("Missing call to super()."), QString(), 0, 0);
1051 return nullptr;
1052 }
1053 }
1054
1055 if (!homeObject) {
1056 ScopedContext ctx(scope, scope.engine->currentContext());
1057 Q_ASSERT(ctx);
1058 while (ctx) {
1059 if (CallContext *c = ctx->asCallContext()) {
1060 f = c->d()->function;
1061 QV4::Function *fn = f->function();
1062 if (fn && !fn->isArrowFunction() && fn->kind != Function::Eval)
1063 break;
1064 }
1065 ctx = ctx->d()->outer;
1066 }
1067 if (f)
1068 homeObject = f->getHomeObject();
1069 }
1070 if (!homeObject) {
1071 scope.engine->throwTypeError();
1072 return nullptr;
1073 }
1074 Q_ASSERT(homeObject);
1075 ScopedObject proto(scope, homeObject->getPrototypeOf());
1076 if (!proto) {
1077 scope.engine->throwTypeError();
1078 return nullptr;
1079 }
1080 return proto;
1081}
1082
1083ReturnedValue Runtime::LoadSuperProperty::call(ExecutionEngine *engine, const Value &property)
1084{
1085 Scope scope(engine);
1086 Object *base = getSuperBase(scope);
1087 if (!base)
1088 return Encode::undefined();
1089 ScopedPropertyKey key(scope, property.toPropertyKey(engine));
1090 if (engine->hasException)
1091 return Encode::undefined();
1092
1093 if (scope.engine->currentStackFrame->isJSTypesFrame()) {
1094 JSTypesStackFrame *frame = static_cast<JSTypesStackFrame *>(
1095 scope.engine->currentStackFrame);
1096 return base->get(key, &(frame->jsFrame->thisObject.asValue<Value>()));
1097 } else {
1100 scope.engine->currentStackFrame);
1101 Scoped<QObjectWrapper> wrapper(scope, QObjectWrapper::wrap(engine, frame->thisObject()));
1102 return base->get(key, wrapper);
1103 }
1104}
1105
1106void Runtime::StoreSuperProperty::call(ExecutionEngine *engine, const Value &property, const Value &value)
1107{
1108 Scope scope(engine);
1109 Object *base = getSuperBase(scope);
1110 if (!base)
1111 return;
1112 ScopedPropertyKey key(scope, property.toPropertyKey(engine));
1113 if (engine->hasException)
1114 return;
1115
1116 bool result;
1117 if (scope.engine->currentStackFrame->isJSTypesFrame()) {
1118 JSTypesStackFrame *frame = static_cast<JSTypesStackFrame *>(
1119 scope.engine->currentStackFrame);
1120 result = base->put(key, value, &(frame->jsFrame->thisObject.asValue<Value>()));
1121 } else {
1124 scope.engine->currentStackFrame);
1125 Scoped<QObjectWrapper> wrapper(scope, QObjectWrapper::wrap(engine, frame->thisObject()));
1126 result = base->put(key, value, wrapper);
1127 }
1128
1129 if (!result && engine->currentStackFrame->v4Function->isStrict())
1130 engine->throwTypeError();
1131}
1132
1133ReturnedValue Runtime::LoadGlobalLookup::call(ExecutionEngine *engine, Function *f, int index)
1134{
1135 Lookup *l = runtimeLookup(f, index);
1136 return l->globalGetter(l, engine);
1137}
1138
1139ReturnedValue Runtime::LoadQmlContextPropertyLookup::call(ExecutionEngine *engine, uint index)
1140{
1141 Lookup *l = runtimeLookup(engine->currentStackFrame->v4Function, index);
1142 return l->qmlContextPropertyGetter(l, engine, nullptr);
1143}
1144
1145ReturnedValue Runtime::GetLookup::call(ExecutionEngine *engine, Function *f, const Value &base, int index)
1146{
1147 Lookup *l = runtimeLookup(f, index);
1148 return l->getter(l, engine, base);
1149}
1150
1151void Runtime::SetLookupSloppy::call(Function *f, const Value &base, int index, const Value &value)
1152{
1153 ExecutionEngine *engine = f->internalClass->engine;
1155 l->setter(l, engine, const_cast<Value &>(base), value);
1156}
1157
1158void Runtime::SetLookupStrict::call(Function *f, const Value &base, int index, const Value &value)
1159{
1160 ExecutionEngine *engine = f->internalClass->engine;
1162 if (!l->setter(l, engine, const_cast<Value &>(base), value))
1163 engine->throwTypeError();
1164}
1165
1166ReturnedValue Runtime::LoadSuperConstructor::call(ExecutionEngine *engine, const Value &t)
1167{
1168 if (engine->currentStackFrame->isJSTypesFrame()) {
1169 JSTypesStackFrame *frame = static_cast<JSTypesStackFrame *>(engine->currentStackFrame);
1170 if (frame->thisObject() != Value::emptyValue().asReturnedValue()) {
1171 // ### TODO: fix line number
1172 return engine->throwReferenceError(
1173 QStringLiteral("super() already called."), QString(), 0, 0);
1174 }
1175 } else {
1176 Q_ASSERT(engine->currentStackFrame->isMetaTypesFrame());
1177 MetaTypesStackFrame *frame = static_cast<MetaTypesStackFrame *>(engine->currentStackFrame);
1178 if (frame->thisObject() != nullptr) {
1179 // ### TODO: fix line number
1180 return engine->throwReferenceError(
1181 QStringLiteral("super() already called."), QString(), 0, 0);
1182 }
1183 }
1184
1185 const FunctionObject *f = t.as<FunctionObject>();
1186 if (!f)
1187 return engine->throwTypeError();
1188 Heap::Object *c = static_cast<const Object &>(t).getPrototypeOf();
1189 if (!c->vtable()->isFunctionObject || !static_cast<Heap::FunctionObject *>(c)->isConstructor())
1190 return engine->throwTypeError();
1191 return c->asReturnedValue();
1192}
1193
1194uint RuntimeHelpers::equalHelper(const Value &x, const Value &y)
1195{
1196 Q_ASSERT(x.type() != y.type() || (x.isManaged() && (x.isString() != y.isString())));
1197
1198 if (x.isNumber() && y.isNumber())
1199 return x.asDouble() == y.asDouble();
1200 if (x.isNull() && y.isUndefined()) {
1201 return true;
1202 } else if (x.isUndefined() && y.isNull()) {
1203 return true;
1204 } else if (x.isNumber() && y.isString()) {
1205 double dy = RuntimeHelpers::toNumber(y);
1206 return x.asDouble() == dy;
1207 } else if (x.isString() && y.isNumber()) {
1208 double dx = RuntimeHelpers::toNumber(x);
1209 return dx == y.asDouble();
1210 } else if (x.isBoolean()) {
1211 return Runtime::CompareEqual::call(Value::fromDouble((double) x.booleanValue()), y);
1212 } else if (y.isBoolean()) {
1213 return Runtime::CompareEqual::call(x, Value::fromDouble((double) y.booleanValue()));
1214 } else {
1215 Object *xo = x.objectValue();
1216 Object *yo = y.objectValue();
1217 if (yo && (x.isNumber() || x.isString())) {
1218 Scope scope(yo->engine());
1219 ScopedValue py(scope, RuntimeHelpers::objectDefaultValue(yo, PREFERREDTYPE_HINT));
1220 return Runtime::CompareEqual::call(x, py);
1221 } else if (xo && (y.isNumber() || y.isString())) {
1222 Scope scope(xo->engine());
1223 ScopedValue px(scope, RuntimeHelpers::objectDefaultValue(xo, PREFERREDTYPE_HINT));
1224 return Runtime::CompareEqual::call(px, y);
1225 }
1226 }
1227
1228 return false;
1229}
1230
1231Bool RuntimeHelpers::strictEqual(const Value &x, const Value &y)
1232{
1233 TRACE2(x, y);
1234
1235 if (x.rawValue() == y.rawValue())
1236 // NaN != NaN
1237 return !x.isNaN();
1238
1239 if (x.isNumber())
1240 return y.isNumber() && x.asDouble() == y.asDouble();
1241 if (x.isManaged()) {
1242 return y.isManaged() && x.cast<Managed>()->isEqualTo(y.cast<Managed>());
1243 }
1244 return false;
1245}
1246
1247QV4::Bool Runtime::CompareGreaterThan::call(const Value &l, const Value &r)
1248{
1249 TRACE2(l, r);
1250 if (l.isInteger() && r.isInteger())
1251 return l.integerValue() > r.integerValue();
1252 if (l.isNumber() && r.isNumber())
1253 return l.asDouble() > r.asDouble();
1254 String *sl = l.stringValue();
1255 String *sr = r.stringValue();
1256 if (sl && sr) {
1257 return sr->lessThan(sl);
1258 }
1259
1260 Object *ro = r.objectValue();
1261 Object *lo = l.objectValue();
1262 if (ro || lo) {
1263 QV4::ExecutionEngine *e = (lo ? lo : ro)->engine();
1264 QV4::Scope scope(e);
1265 QV4::ScopedValue pl(scope, lo ? RuntimeHelpers::objectDefaultValue(lo, QV4::NUMBER_HINT) : l.asReturnedValue());
1266 QV4::ScopedValue pr(scope, ro ? RuntimeHelpers::objectDefaultValue(ro, QV4::NUMBER_HINT) : r.asReturnedValue());
1267 return Runtime::CompareGreaterThan::call(pl, pr);
1268 }
1269
1270 double dl = RuntimeHelpers::toNumber(l);
1271 double dr = RuntimeHelpers::toNumber(r);
1272 return dl > dr;
1273}
1274
1275QV4::Bool Runtime::CompareLessThan::call(const Value &l, const Value &r)
1276{
1277 TRACE2(l, r);
1278 if (l.isInteger() && r.isInteger())
1279 return l.integerValue() < r.integerValue();
1280 if (l.isNumber() && r.isNumber())
1281 return l.asDouble() < r.asDouble();
1282 String *sl = l.stringValue();
1283 String *sr = r.stringValue();
1284 if (sl && sr) {
1285 return sl->lessThan(sr);
1286 }
1287
1288 Object *ro = r.objectValue();
1289 Object *lo = l.objectValue();
1290 if (ro || lo) {
1291 QV4::ExecutionEngine *e = (lo ? lo : ro)->engine();
1292 QV4::Scope scope(e);
1293 QV4::ScopedValue pl(scope, lo ? RuntimeHelpers::objectDefaultValue(lo, QV4::NUMBER_HINT) : l.asReturnedValue());
1294 QV4::ScopedValue pr(scope, ro ? RuntimeHelpers::objectDefaultValue(ro, QV4::NUMBER_HINT) : r.asReturnedValue());
1295 return Runtime::CompareLessThan::call(pl, pr);
1296 }
1297
1298 double dl = RuntimeHelpers::toNumber(l);
1299 double dr = RuntimeHelpers::toNumber(r);
1300 return dl < dr;
1301}
1302
1303QV4::Bool Runtime::CompareGreaterEqual::call(const Value &l, const Value &r)
1304{
1305 TRACE2(l, r);
1306 if (l.isInteger() && r.isInteger())
1307 return l.integerValue() >= r.integerValue();
1308 if (l.isNumber() && r.isNumber())
1309 return l.asDouble() >= r.asDouble();
1310 String *sl = l.stringValue();
1311 String *sr = r.stringValue();
1312 if (sl && sr) {
1313 return !sl->lessThan(sr);
1314 }
1315
1316 Object *ro = r.objectValue();
1317 Object *lo = l.objectValue();
1318 if (ro || lo) {
1319 QV4::ExecutionEngine *e = (lo ? lo : ro)->engine();
1320 QV4::Scope scope(e);
1321 QV4::ScopedValue pl(scope, lo ? RuntimeHelpers::objectDefaultValue(lo, QV4::NUMBER_HINT) : l.asReturnedValue());
1322 QV4::ScopedValue pr(scope, ro ? RuntimeHelpers::objectDefaultValue(ro, QV4::NUMBER_HINT) : r.asReturnedValue());
1323 return Runtime::CompareGreaterEqual::call(pl, pr);
1324 }
1325
1326 double dl = RuntimeHelpers::toNumber(l);
1327 double dr = RuntimeHelpers::toNumber(r);
1328 return dl >= dr;
1329}
1330
1331QV4::Bool Runtime::CompareLessEqual::call(const Value &l, const Value &r)
1332{
1333 TRACE2(l, r);
1334 if (l.isInteger() && r.isInteger())
1335 return l.integerValue() <= r.integerValue();
1336 if (l.isNumber() && r.isNumber())
1337 return l.asDouble() <= r.asDouble();
1338 String *sl = l.stringValue();
1339 String *sr = r.stringValue();
1340 if (sl && sr) {
1341 return !sr->lessThan(sl);
1342 }
1343
1344 Object *ro = r.objectValue();
1345 Object *lo = l.objectValue();
1346 if (ro || lo) {
1347 QV4::ExecutionEngine *e = (lo ? lo : ro)->engine();
1348 QV4::Scope scope(e);
1349 QV4::ScopedValue pl(scope, lo ? RuntimeHelpers::objectDefaultValue(lo, QV4::NUMBER_HINT) : l.asReturnedValue());
1350 QV4::ScopedValue pr(scope, ro ? RuntimeHelpers::objectDefaultValue(ro, QV4::NUMBER_HINT) : r.asReturnedValue());
1351 return Runtime::CompareLessEqual::call(pl, pr);
1352 }
1353
1354 double dl = RuntimeHelpers::toNumber(l);
1355 double dr = RuntimeHelpers::toNumber(r);
1356 return dl <= dr;
1357}
1358
1359Bool Runtime::CompareInstanceof::call(ExecutionEngine *engine, const Value &left, const Value &right)
1360{
1361 TRACE2(left, right);
1362
1363 Scope scope(engine);
1364 ScopedValue v(scope, Instanceof::call(engine, left, right));
1365 return v->booleanValue();
1366}
1367
1368uint Runtime::CompareIn::call(ExecutionEngine *engine, const Value &left, const Value &right)
1369{
1370 TRACE2(left, right);
1371
1372 Scope scope(engine);
1373 ScopedValue v(scope, In::call(engine, left, right));
1374 return v->booleanValue();
1375}
1376
1378{
1379 QString objectAsString = QStringLiteral("[null]");
1380 if (!thisObject->isUndefined())
1381 objectAsString = thisObject->toQStringNoThrow();
1382 QString msg = QStringLiteral("Property '%1' of object %2 is not a function")
1383 .arg(propertyName, objectAsString);
1384 return engine->throwTypeError(msg);
1385}
1386
1387ReturnedValue Runtime::CallGlobalLookup::call(ExecutionEngine *engine, uint index, Value argv[], int argc)
1388{
1389 Scope scope(engine);
1390 Lookup *l = runtimeLookup(engine->currentStackFrame->v4Function, index);
1391 Value function = Value::fromReturnedValue(l->globalGetter(l, engine));
1392 Value thisObject = Value::undefinedValue();
1393 if (!function.isFunctionObject()) {
1394 return throwPropertyIsNotAFunctionTypeError(engine, &thisObject,
1395 engine->currentStackFrame->v4Function->compilationUnit->runtimeStrings[l->nameIndex]->toQString());
1396 }
1397
1398 return checkedResult(engine, static_cast<FunctionObject &>(function).call(
1399 &thisObject, argv, argc));
1400}
1401
1402ReturnedValue Runtime::CallQmlContextPropertyLookup::call(ExecutionEngine *engine, uint index,
1403 Value *argv, int argc)
1404{
1405 Scope scope(engine);
1406 ScopedValue thisObject(scope);
1407 Lookup *l = runtimeLookup(engine->currentStackFrame->v4Function, index);
1408 Value function = Value::fromReturnedValue(l->qmlContextPropertyGetter(l, engine, thisObject));
1409 if (!function.isFunctionObject()) {
1411 engine->currentStackFrame->v4Function->compilationUnit->runtimeStrings[l->nameIndex]->toQString());
1412 }
1413
1414 return checkedResult(engine, static_cast<FunctionObject &>(function).call(
1415 thisObject, argv, argc));
1416}
1417
1418ReturnedValue Runtime::CallPossiblyDirectEval::call(ExecutionEngine *engine, Value *argv, int argc)
1419{
1420 Scope scope(engine);
1421 ScopedValue thisObject(scope);
1422
1424 scope, engine->currentContext()->getPropertyAndBase(engine->id_eval(), thisObject));
1425 if (engine->hasException)
1426 return Encode::undefined();
1427
1428 if (!function)
1429 return throwPropertyIsNotAFunctionTypeError(engine, thisObject, QLatin1String("eval"));
1430
1431 if (function->d() == engine->evalFunction()->d())
1432 return static_cast<EvalFunction *>(function.getPointer())->evalCall(thisObject, argv, argc, true);
1433
1434 return checkedResult(engine, function->call(thisObject, argv, argc));
1435}
1436
1437ReturnedValue Runtime::CallName::call(ExecutionEngine *engine, int nameIndex, Value *argv, int argc)
1438{
1439 Scope scope(engine);
1440 ScopedValue thisObject(scope);
1441 ScopedString name(scope, engine->currentStackFrame->v4Function->compilationUnit->runtimeStrings[nameIndex]);
1442
1443 ScopedFunctionObject f(scope, engine->currentContext()->getPropertyAndBase(name, thisObject));
1444 if (engine->hasException)
1445 return Encode::undefined();
1446
1447 if (!f) {
1449 engine, thisObject, engine->currentStackFrame->v4Function->compilationUnit
1450 ->runtimeStrings[nameIndex]->toQString());
1451 }
1452
1453 return checkedResult(engine, f->call(thisObject, argv, argc));
1454}
1455
1456ReturnedValue Runtime::CallProperty::call(ExecutionEngine *engine, const Value &baseRef, int nameIndex, Value *argv, int argc)
1457{
1458 const Value *base = &baseRef;
1459 Scope scope(engine);
1461 scope,
1462 engine->currentStackFrame->v4Function->compilationUnit->runtimeStrings[nameIndex]);
1463 ScopedObject lookupObject(scope, base);
1464
1465 if (!lookupObject) {
1466 Q_ASSERT(!base->isEmpty());
1467 if (base->isNullOrUndefined()) {
1468 QString message = QStringLiteral("Cannot call method '%1' of %2")
1469 .arg(name->toQString(), base->toQStringNoThrow());
1470 return engine->throwTypeError(message);
1471 }
1472
1473 if (base->isManaged()) {
1474 const Managed *m = static_cast<const Managed *>(base);
1475 lookupObject = m->internalClass()->prototype;
1476 Q_ASSERT(m->internalClass()->prototype);
1477 } else {
1478 lookupObject = RuntimeHelpers::convertToObject(engine, *base);
1479 if (engine->hasException) // type error
1480 return Encode::undefined();
1481 if (!engine->currentStackFrame->v4Function->isStrict())
1482 base = lookupObject;
1483 }
1484 }
1485
1486 ScopedFunctionObject f(scope, static_cast<Object *>(lookupObject)->get(name));
1487
1488 if (!f) {
1489 QString error = QStringLiteral("Property '%1' of object %2 is not a function")
1490 .arg(name->toQString(),
1491 base->toQStringNoThrow());
1492 return engine->throwTypeError(error);
1493 }
1494
1495 return checkedResult(engine, f->call(base, argv, argc));
1496}
1497
1498ReturnedValue Runtime::CallPropertyLookup::call(ExecutionEngine *engine, const Value &base, uint index, Value *argv, int argc)
1499{
1500 Lookup *l = runtimeLookup(engine->currentStackFrame->v4Function, index);
1501 // ok to have the value on the stack here
1502 Value f = Value::fromReturnedValue(l->getter(l, engine, base));
1503
1504 if (!f.isFunctionObject())
1505 return engine->throwTypeError();
1506
1507 return checkedResult(engine, static_cast<FunctionObject &>(f).call(&base, argv, argc));
1508}
1509
1510ReturnedValue Runtime::CallValue::call(ExecutionEngine *engine, const Value &func, Value *argv, int argc)
1511{
1512 if (!func.isFunctionObject())
1513 return engine->throwTypeError(QStringLiteral("%1 is not a function").arg(func.toQStringNoThrow()));
1514 Value undef = Value::undefinedValue();
1515 return checkedResult(engine, static_cast<const FunctionObject &>(func).call(
1516 &undef, argv, argc));
1517}
1518
1519ReturnedValue Runtime::CallWithReceiver::call(ExecutionEngine *engine, const Value &func,
1520 const Value &thisObject, Value argv[], int argc)
1521{
1522 if (!func.isFunctionObject())
1523 return engine->throwTypeError(QStringLiteral("%1 is not a function").arg(func.toQStringNoThrow()));
1524 return checkedResult(engine, static_cast<const FunctionObject &>(func).call(
1525 &thisObject, argv, argc));
1526}
1527
1528struct CallArgs {
1530 int argc;
1531};
1532
1533static CallArgs createSpreadArguments(Scope &scope, Value *argv, int argc)
1534{
1535 ScopedValue it(scope);
1536 ScopedValue done(scope);
1537
1538 int argCount = 0;
1539
1540 Value *v = scope.alloc<Scope::Uninitialized>();
1541 Value *arguments = v;
1542 for (int i = 0; i < argc; ++i) {
1543 if (!argv[i].isEmpty()) {
1544 *v = argv[i];
1545 ++argCount;
1546 v = scope.alloc<Scope::Uninitialized>();
1547 continue;
1548 }
1549 // spread element
1550 ++i;
1551 it = Runtime::GetIterator::call(scope.engine, argv[i], /* ForInIterator */ 1);
1552 if (scope.hasException())
1553 return { nullptr, 0 };
1554 while (1) {
1555 done = Runtime::IteratorNext::call(scope.engine, it, v);
1556 if (scope.hasException())
1557 return { nullptr, 0 };
1558 Q_ASSERT(done->isBoolean());
1559 if (done->booleanValue())
1560 break;
1561 ++argCount;
1562 constexpr auto safetyMargin = 100; // leave some space on the stack for actual work with the elements
1563 if (qint64(scope.engine->jsStackLimit - scope.engine->jsStackTop) < safetyMargin) {
1564 scope.engine->throwRangeError(QLatin1String("Too many elements in array to use it with the spread operator"));
1565 return { nullptr, 0 };
1566 }
1567 v = scope.alloc<Scope::Uninitialized>();
1568 }
1569 }
1570 return { arguments, argCount };
1571}
1572
1573ReturnedValue Runtime::CallWithSpread::call(ExecutionEngine *engine, const Value &function, const Value &thisObject, Value *argv, int argc)
1574{
1575 Q_ASSERT(argc >= 1);
1576 if (!function.isFunctionObject())
1577 return engine->throwTypeError();
1578
1579 Scope scope(engine);
1580 CallArgs arguments = createSpreadArguments(scope, argv, argc);
1581 if (engine->hasException)
1582 return Encode::undefined();
1583
1584 return checkedResult(engine, static_cast<const FunctionObject &>(function).call(
1585 &thisObject, arguments.argv, arguments.argc));
1586}
1587
1588ReturnedValue Runtime::Construct::call(ExecutionEngine *engine, const Value &function, const Value &newTarget, Value *argv, int argc)
1589{
1590 if (!function.isFunctionObject())
1591 return engine->throwTypeError();
1592
1593 return static_cast<const FunctionObject &>(function).callAsConstructor(argv, argc, &newTarget);
1594}
1595
1596ReturnedValue Runtime::ConstructWithSpread::call(ExecutionEngine *engine, const Value &function, const Value &newTarget, Value *argv, int argc)
1597{
1598 if (!function.isFunctionObject())
1599 return engine->throwTypeError();
1600
1601 Scope scope(engine);
1602 CallArgs arguments = createSpreadArguments(scope, argv, argc);
1603 if (engine->hasException)
1604 return Encode::undefined();
1605
1606 return static_cast<const FunctionObject &>(function).callAsConstructor(arguments.argv, arguments.argc, &newTarget);
1607}
1608
1610{
1611 // IMPORTANT! The JIT assumes that this method has the same amount (or less) arguments than
1612 // the jitted function, so it can safely do a tail call.
1613
1614 Value *tos = engine->jsStackTop;
1615 const Value &function = tos[StackOffsets::tailCall_function];
1616 const Value &thisObject = tos[StackOffsets::tailCall_thisObject];
1617 Value *argv = reinterpret_cast<Value *>(frame->jsFrame) + tos[StackOffsets::tailCall_argv].int_32();
1618 int argc = tos[StackOffsets::tailCall_argc].int_32();
1619 Q_ASSERT(argc >= 0);
1620
1621 if (!function.isFunctionObject())
1622 return engine->throwTypeError();
1623
1624 const FunctionObject &fo = static_cast<const FunctionObject &>(function);
1625 if (!frame->callerCanHandleTailCall() || !fo.canBeTailCalled() || engine->debugger()
1626 || unsigned(argc) > fo.formalParameterCount()) {
1627 // Cannot tailcall, do a normal call:
1628 return checkedResult(engine, fo.call(&thisObject, argv, argc));
1629 }
1630
1631 memcpy(frame->jsFrame->args, argv, argc * sizeof(Value));
1632 frame->init(fo.function(), frame->jsFrame->argValues<Value>(), argc,
1633 frame->callerCanHandleTailCall());
1634 frame->setupJSFrame(frame->framePointer(), fo, fo.scope(), thisObject,
1635 Primitive::undefinedValue());
1636 engine->jsStackTop = frame->framePointer() + frame->requiredJSStackFrameSize();
1637 frame->setPendingTailCall(true);
1638 return Encode::undefined();
1639}
1640
1641void Runtime::ThrowException::call(ExecutionEngine *engine, const Value &value)
1642{
1643 if (!value.isEmpty())
1645}
1646
1647ReturnedValue Runtime::TypeofValue::call(ExecutionEngine *engine, const Value &value)
1648{
1649 Scope scope(engine);
1650 ScopedString res(scope);
1651 switch (value.type()) {
1652 case Value::Undefined_Type:
1653 res = engine->id_undefined();
1654 break;
1655 case Value::Null_Type:
1656 res = engine->id_object();
1657 break;
1658 case Value::Boolean_Type:
1659 res = engine->id_boolean();
1660 break;
1661 case Value::Managed_Type:
1662 if (value.isString())
1663 res = engine->id_string();
1664 else if (value.isSymbol())
1665 res = engine->id_symbol();
1666 else if (value.objectValue()->as<FunctionObject>())
1667 res = engine->id_function();
1668 else
1669 res = engine->id_object(); // ### implementation-defined
1670 break;
1671 default:
1672 res = engine->id_number();
1673 break;
1674 }
1675 return res.asReturnedValue();
1676}
1677
1678QV4::ReturnedValue Runtime::TypeofName::call(ExecutionEngine *engine, int nameIndex)
1679{
1680 Scope scope(engine);
1681 ScopedString name(scope, engine->currentStackFrame->v4Function->compilationUnit->runtimeStrings[nameIndex]);
1682 ScopedValue prop(scope, engine->currentContext()->getProperty(name));
1683 // typeof doesn't throw. clear any possible exception
1684 scope.engine->hasException = false;
1685 return TypeofValue::call(engine, prop);
1686}
1687
1688void Runtime::PushCallContext::call(JSTypesStackFrame *frame)
1689{
1690 frame->jsFrame->context = ExecutionContext::newCallContext(frame)->asReturnedValue();
1691}
1692
1693ReturnedValue Runtime::PushWithContext::call(ExecutionEngine *engine, const Value &acc)
1694{
1695 Q_ASSERT(engine->currentStackFrame->isJSTypesFrame());
1696 CallData *jsFrame = static_cast<JSTypesStackFrame *>(engine->currentStackFrame)->jsFrame;
1697 Value &newAcc = jsFrame->accumulator.asValue<Value>();
1698 newAcc = Value::fromHeapObject(acc.toObject(engine));
1699 if (!engine->hasException) {
1700 Q_ASSERT(newAcc.isObject());
1701 const Object &obj = static_cast<const Object &>(newAcc);
1702 Value &context = jsFrame->context.asValue<Value>();
1703 auto ec = static_cast<const ExecutionContext *>(&context);
1704 context = ec->newWithContext(obj.d())->asReturnedValue();
1705 }
1706 return newAcc.asReturnedValue();
1707}
1708
1709void Runtime::PushCatchContext::call(ExecutionEngine *engine, int blockIndex, int exceptionVarNameIndex)
1710{
1711 Q_ASSERT(engine->currentStackFrame->isJSTypesFrame());
1712 auto name = engine->currentStackFrame->v4Function->compilationUnit->runtimeStrings[exceptionVarNameIndex];
1713 static_cast<JSTypesStackFrame *>(engine->currentStackFrame)->jsFrame->context
1714 = ExecutionContext::newCatchContext(engine->currentStackFrame, blockIndex, name)->asReturnedValue();
1715}
1716
1717void Runtime::PushBlockContext::call(ExecutionEngine *engine, int index)
1718{
1719 Q_ASSERT(engine->currentStackFrame->isJSTypesFrame());
1720 static_cast<JSTypesStackFrame *>(engine->currentStackFrame)->jsFrame->context
1721 = ExecutionContext::newBlockContext(engine->currentStackFrame, index)->asReturnedValue();
1722}
1723
1724void Runtime::CloneBlockContext::call(ExecutionEngine *engine)
1725{
1726 Q_ASSERT(engine->currentStackFrame->isJSTypesFrame());
1727 auto frame = static_cast<JSTypesStackFrame *>(engine->currentStackFrame);
1728 auto context = static_cast<Heap::CallContext *>(
1729 Value::fromStaticValue(frame->jsFrame->context).m());
1730 frame->jsFrame->context =
1731 ExecutionContext::cloneBlockContext(engine, context)->asReturnedValue();
1732}
1733
1734void Runtime::PushScriptContext::call(ExecutionEngine *engine, int index)
1735{
1736 Q_ASSERT(engine->currentStackFrame->isJSTypesFrame());
1737 Q_ASSERT(engine->currentContext()->d()->type == Heap::ExecutionContext::Type_GlobalContext ||
1738 engine->currentContext()->d()->type == Heap::ExecutionContext::Type_QmlContext);
1739 ReturnedValue c = ExecutionContext::newBlockContext(engine->currentStackFrame, index)->asReturnedValue();
1740 engine->setScriptContext(c);
1741 static_cast<JSTypesStackFrame *>(engine->currentStackFrame)->jsFrame->context = c;
1742}
1743
1744void Runtime::PopScriptContext::call(ExecutionEngine *engine)
1745{
1746 Q_ASSERT(engine->currentStackFrame->isJSTypesFrame());
1747 ReturnedValue root = engine->rootContext()->asReturnedValue();
1748 engine->setScriptContext(root);
1749 static_cast<JSTypesStackFrame *>(engine->currentStackFrame)->jsFrame->context = root;
1750}
1751
1752void Runtime::ThrowReferenceError::call(ExecutionEngine *engine, int nameIndex)
1753{
1754 Scope scope(engine);
1755 ScopedString name(scope, engine->currentStackFrame->v4Function->compilationUnit->runtimeStrings[nameIndex]);
1756 engine->throwReferenceError(name);
1757}
1758
1759void Runtime::ThrowOnNullOrUndefined::call(ExecutionEngine *engine, const Value &v)
1760{
1761 if (v.isNullOrUndefined())
1762 engine->throwTypeError();
1763}
1764
1765ReturnedValue Runtime::ConvertThisToObject::call(ExecutionEngine *engine, const Value &t)
1766{
1767 if (!t.isObject()) {
1768 if (t.isNullOrUndefined()) {
1769 return engine->globalObject->asReturnedValue();
1770 } else {
1771 return t.toObject(engine)->asReturnedValue();
1772 }
1773 }
1774 return t.asReturnedValue();
1775}
1776
1777void Runtime::DeclareVar::call(ExecutionEngine *engine, Bool deletable, int nameIndex)
1778{
1779 Scope scope(engine);
1780 ScopedString name(scope, engine->currentStackFrame->v4Function->compilationUnit->runtimeStrings[nameIndex]);
1781 engine->currentContext()->createMutableBinding(name, deletable);
1782}
1783
1785{
1786 return engine->newArrayObject(values, length)->asReturnedValue();
1787}
1788
1789ReturnedValue Runtime::ObjectLiteral::call(ExecutionEngine *engine, int classId, QV4::Value args[], int argc)
1790{
1791 Scope scope(engine);
1792 Scoped<InternalClass> klass(scope, engine->currentStackFrame->v4Function->compilationUnit->runtimeClasses[classId]);
1793 ScopedObject o(scope, engine->newObject(klass->d()));
1794
1795 Q_ASSERT(uint(argc) >= klass->d()->size);
1796
1797 for (uint i = 0; i < klass->d()->size; ++i)
1798 o->setProperty(i, *args++);
1799
1800 Q_ASSERT((argc - klass->d()->size) % 3 == 0);
1801 int additionalArgs = (argc - int(klass->d()->size))/3;
1802
1803 if (!additionalArgs)
1804 return o->asReturnedValue();
1805
1806 ScopedPropertyKey name(scope);
1807 ScopedProperty pd(scope);
1808 ScopedFunctionObject fn(scope);
1809 ScopedString fnName(scope);
1810 ScopedValue value(scope);
1811 for (int i = 0; i < additionalArgs; ++i) {
1812 Q_ASSERT(args->isInteger());
1814 name = args[1].toPropertyKey(engine);
1815 value = args[2];
1816 if (engine->hasException)
1817 return Encode::undefined();
1818 if (arg != ObjectLiteralArgument::Value) {
1819 Q_ASSERT(args[2].isInteger());
1820 int functionId = args[2].integerValue();
1821 QV4::Function *clos = engine->currentStackFrame->v4Function->executableCompilationUnit()
1822 ->runtimeFunctions[functionId];
1823 Q_ASSERT(clos);
1824
1825 PropertyKey::FunctionNamePrefix prefix = PropertyKey::None;
1826 if (arg == ObjectLiteralArgument::Getter)
1827 prefix = PropertyKey::Getter;
1828 else if (arg == ObjectLiteralArgument::Setter)
1829 prefix = PropertyKey::Setter;
1830 else
1831 arg = ObjectLiteralArgument::Value;
1832 fnName = name->asFunctionName(engine, prefix);
1833
1834 ExecutionContext *current = engine->currentContext();
1835 if (clos->isGenerator())
1836 value = MemberGeneratorFunction::create(current, clos, o, fnName)->asReturnedValue();
1837 else
1838 value = FunctionObject::createMemberFunction(current, clos, o, fnName)->asReturnedValue();
1839 } else if (args[2].isFunctionObject()) {
1840 fn = static_cast<const FunctionObject &>(args[2]);
1841
1842 fnName = name->asFunctionName(engine, PropertyKey::None);
1843 fn->setName(fnName);
1844 }
1845 Q_ASSERT(arg != ObjectLiteralArgument::Method);
1846 Q_ASSERT(arg == ObjectLiteralArgument::Value || value->isFunctionObject());
1847 if (arg == ObjectLiteralArgument::Value || arg == ObjectLiteralArgument::Getter) {
1848 pd->value = value;
1849 pd->set = Value::emptyValue();
1850 } else {
1851 pd->value = Value::emptyValue();
1852 pd->set = value;
1853 }
1854 bool ok = o->defineOwnProperty(name, pd, (arg == ObjectLiteralArgument::Value ? Attr_Data : Attr_Accessor));
1855 if (!ok)
1856 return engine->throwTypeError();
1857
1858 args += 3;
1859 }
1860 return o.asReturnedValue();
1861}
1862
1863ReturnedValue Runtime::CreateClass::call(ExecutionEngine *engine, int classIndex,
1864 const Value &superClass, Value computedNames[])
1865{
1867 = engine->currentStackFrame->v4Function->executableCompilationUnit();
1868 const QV4::CompiledData::Class *cls = unit->unitData()->classAt(classIndex);
1869
1870 Scope scope(engine);
1871 ScopedObject protoParent(scope, engine->objectPrototype());
1872 ScopedObject constructorParent(scope, engine->functionPrototype());
1873 if (!superClass.isEmpty()) {
1874 if (superClass.isNull()) {
1875 protoParent = Encode::null();
1876 } else {
1877 const FunctionObject *superFunction = superClass.as<FunctionObject>();
1878 // ### check that the heritage object is a constructor
1879 if (!superFunction || !superFunction->isConstructor())
1880 return engine->throwTypeError(QStringLiteral("The superclass is not a function object."));
1881 const FunctionObject *s = static_cast<const FunctionObject *>(&superClass);
1882 ScopedValue result(scope, s->get(scope.engine->id_prototype()));
1883 if (!result->isObject() && !result->isNull())
1884 return engine->throwTypeError(QStringLiteral("The value of the superclass's prototype property is not an object."));
1885 protoParent = *result;
1886 constructorParent = superClass;
1887 }
1888 }
1889
1890 ScopedObject proto(scope, engine->newObject());
1891 proto->setPrototypeUnchecked(protoParent);
1892 ExecutionContext *current = engine->currentContext();
1893
1894 ScopedFunctionObject constructor(scope);
1895 QV4::Function *f = cls->constructorFunction != UINT_MAX ? unit->runtimeFunctions[cls->constructorFunction] : nullptr;
1896 constructor = FunctionObject::createConstructorFunction(current, f, proto, !superClass.isEmpty())->asReturnedValue();
1897 constructor->setPrototypeUnchecked(constructorParent);
1898 Value argCount = Value::fromInt32(f ? f->nFormals : 0);
1899 constructor->defineReadonlyConfigurableProperty(scope.engine->id_length(), argCount);
1900 constructor->defineReadonlyConfigurableProperty(engine->id_prototype(), proto);
1901 proto->defineDefaultProperty(engine->id_constructor(), constructor);
1902
1903 ScopedString name(scope);
1904 if (cls->nameIndex != UINT_MAX) {
1905 name = unit->runtimeStrings[cls->nameIndex];
1906 constructor->defineReadonlyConfigurableProperty(engine->id_name(), name);
1907 }
1908
1909 ScopedObject receiver(scope, *constructor);
1910 ScopedPropertyKey propertyName(scope);
1912 ScopedProperty property(scope);
1914 for (uint i = 0; i < cls->nStaticMethods + cls->nMethods; ++i) {
1915 if (i == cls->nStaticMethods)
1916 receiver = proto;
1917 if (methods[i].name == UINT_MAX) {
1918 propertyName = computedNames->toPropertyKey(engine);
1919 if (propertyName == scope.engine->id_prototype()->propertyKey() && receiver->d() == constructor->d())
1920 return engine->throwTypeError(QStringLiteral("Cannot declare a static method named 'prototype'."));
1921 if (engine->hasException)
1922 return Encode::undefined();
1923 ++computedNames;
1924 } else {
1925 name = unit->runtimeStrings[methods[i].name];
1926 propertyName = name->toPropertyKey();
1927 }
1928 QV4::Function *f = unit->runtimeFunctions[methods[i].function];
1929 Q_ASSERT(f);
1930 PropertyKey::FunctionNamePrefix prefix = PropertyKey::None;
1931 if (methods[i].type == CompiledData::Method::Getter)
1932 prefix = PropertyKey::Getter;
1933 else if (methods[i].type == CompiledData::Method::Setter)
1934 prefix = PropertyKey::Setter;
1935
1936 name = propertyName->asFunctionName(engine, prefix);
1937
1938 if (f->isGenerator())
1939 function = MemberGeneratorFunction::create(current, f, receiver, name);
1940 else
1941 function = FunctionObject::createMemberFunction(current, f, receiver, name);
1943 PropertyAttributes attributes;
1944 switch (methods[i].type) {
1945 case CompiledData::Method::Getter:
1946 property->setGetter(function);
1947 property->set = Value::emptyValue();
1948 attributes = Attr_Accessor|Attr_NotEnumerable;
1949 break;
1950 case CompiledData::Method::Setter:
1951 property->value = Value::emptyValue();
1952 property->setSetter(function);
1953 attributes = Attr_Accessor|Attr_NotEnumerable;
1954 break;
1955 default: // Regular
1956 property->value = function;
1957 property->set = Value::emptyValue();
1958 attributes = Attr_Data|Attr_NotEnumerable;
1959 break;
1960 }
1961 receiver->defineOwnProperty(propertyName, property, attributes);
1962 }
1963
1964 return constructor->asReturnedValue();
1965}
1966
1967QV4::ReturnedValue Runtime::CreateMappedArgumentsObject::call(ExecutionEngine *engine)
1968{
1969 Q_ASSERT(engine->currentContext()->d()->type == Heap::ExecutionContext::Type_CallContext);
1970 Heap::InternalClass *ic = engine->internalClasses(EngineBase::Class_ArgumentsObject);
1971 return engine->memoryManager->allocObject<ArgumentsObject>(ic, engine->currentStackFrame)->asReturnedValue();
1972}
1973
1974QV4::ReturnedValue Runtime::CreateUnmappedArgumentsObject::call(ExecutionEngine *engine)
1975{
1976 Q_ASSERT(engine->currentStackFrame->isJSTypesFrame());
1977 Heap::InternalClass *ic = engine->internalClasses(EngineBase::Class_StrictArgumentsObject);
1978 return engine->memoryManager->allocObject<StrictArgumentsObject>(
1979 ic, static_cast<JSTypesStackFrame *>(engine->currentStackFrame))->asReturnedValue();
1980}
1981
1982QV4::ReturnedValue Runtime::CreateRestParameter::call(ExecutionEngine *engine, int argIndex)
1983{
1984 Q_ASSERT(engine->currentStackFrame->isJSTypesFrame());
1985 JSTypesStackFrame *frame = static_cast<JSTypesStackFrame *>(engine->currentStackFrame);
1986 const Value *values = frame->argv() + argIndex;
1987 int nValues = frame->argc() - argIndex;
1988 if (nValues <= 0)
1989 return engine->newArrayObject(0)->asReturnedValue();
1990 return engine->newArrayObject(values, nValues)->asReturnedValue();
1991}
1992
1993ReturnedValue Runtime::RegexpLiteral::call(ExecutionEngine *engine, int id)
1994{
1995 const auto val
1996 = engine->currentStackFrame->v4Function->compilationUnit->runtimeRegularExpressions[id];
1997 Heap::RegExpObject *ro = engine->newRegExpObject(Value::fromStaticValue(val).as<RegExp>());
1998 return ro->asReturnedValue();
1999}
2000
2001ReturnedValue Runtime::ToObject::call(ExecutionEngine *engine, const Value &obj)
2002{
2003 if (obj.isObject())
2004 return obj.asReturnedValue();
2005
2006 return obj.toObject(engine)->asReturnedValue();
2007}
2008
2009Bool Runtime::ToBoolean::call(const Value &obj)
2010{
2011 return obj.toBoolean();
2012}
2013
2014ReturnedValue Runtime::ToNumber::call(ExecutionEngine *, const Value &v)
2015{
2016 return Encode(v.toNumber());
2017}
2018
2019ReturnedValue Runtime::UMinus::call(const Value &value)
2020{
2021 TRACE1(value);
2022
2023 // +0 != -0, so we need to convert to double when negating 0
2024 if (value.isInteger() && value.integerValue() &&
2025 value.integerValue() != std::numeric_limits<int>::min())
2026 return Encode(-value.integerValue());
2027 else {
2028 double n = RuntimeHelpers::toNumber(value);
2029 return Encode(-n);
2030 }
2031}
2032
2033// binary operators
2034
2035ReturnedValue Runtime::Add::call(ExecutionEngine *engine, const Value &left, const Value &right)
2036{
2037 TRACE2(left, right);
2038
2039 if (Q_LIKELY(left.integerCompatible() && right.integerCompatible()))
2040 return add_int32(left.integerValue(), right.integerValue());
2041 if (left.isNumber() && right.isNumber())
2042 return Value::fromDouble(left.asDouble() + right.asDouble()).asReturnedValue();
2043
2044 return RuntimeHelpers::addHelper(engine, left, right);
2045}
2046
2047ReturnedValue Runtime::Sub::call(const Value &left, const Value &right)
2048{
2049 TRACE2(left, right);
2050
2051 if (Q_LIKELY(left.integerCompatible() && right.integerCompatible()))
2052 return sub_int32(left.integerValue(), right.integerValue());
2053
2054 double lval = left.isNumber() ? left.asDouble() : left.toNumberImpl();
2055 double rval = right.isNumber() ? right.asDouble() : right.toNumberImpl();
2056
2057 return Value::fromDouble(lval - rval).asReturnedValue();
2058}
2059
2060ReturnedValue Runtime::Mul::call(const Value &left, const Value &right)
2061{
2062 TRACE2(left, right);
2063
2064 if (Q_LIKELY(left.integerCompatible() && right.integerCompatible()))
2065 return mul_int32(left.integerValue(), right.integerValue());
2066
2067 double lval = left.isNumber() ? left.asDouble() : left.toNumberImpl();
2068 double rval = right.isNumber() ? right.asDouble() : right.toNumberImpl();
2069
2070 return Value::fromDouble(lval * rval).asReturnedValue();
2071}
2072
2073ReturnedValue Runtime::Div::call(const Value &left, const Value &right)
2074{
2075 TRACE2(left, right);
2076
2077 if (Value::integerCompatible(left, right)) {
2078 int lval = left.integerValue();
2079 int rval = right.integerValue();
2080 if (rval != 0 // division by zero should result in a NaN
2081 && !(lval == std::numeric_limits<int>::min() && rval == -1) // doesn't fit in int
2082 && (lval % rval == 0) // fractions can't be stored in an int
2083 && !(lval == 0 && rval < 0)) // 0 / -something results in -0.0
2084 return Encode(int(lval / rval));
2085 else
2086 return Encode(double(lval) / rval);
2087 }
2088
2089 double lval = left.toNumber();
2090 double rval = right.toNumber();
2091 return Value::fromDouble(lval / rval).asReturnedValue();
2092}
2093
2094ReturnedValue Runtime::Mod::call(const Value &left, const Value &right)
2095{
2096 TRACE2(left, right);
2097
2098 if (Value::integerCompatible(left, right) && left.integerValue() >= 0 && right.integerValue() > 0) {
2099 // special cases are handled by fmod, among them:
2100 // - arithmic execeptions for ints in c++, eg: INT_MIN % -1
2101 // - undefined behavior in c++, e.g.: anything % 0
2102 // - uncommon cases which would complicate the condition, e.g.: negative integers
2103 // (this makes sure that -1 % 1 == -0 by passing it to fmod)
2104 return Encode(left.integerValue() % right.integerValue());
2105 }
2106
2107 double lval = RuntimeHelpers::toNumber(left);
2108 double rval = RuntimeHelpers::toNumber(right);
2109#ifdef fmod
2110# undef fmod
2111#endif
2112 return Value::fromDouble(std::fmod(lval, rval)).asReturnedValue();
2113}
2114
2115ReturnedValue Runtime::Exp::call(const Value &base, const Value &exp)
2116{
2117 double b = base.toNumber();
2118 double e = exp.toNumber();
2120}
2121
2122ReturnedValue Runtime::BitAnd::call(const Value &left, const Value &right)
2123{
2124 TRACE2(left, right);
2125
2126 int lval = left.toInt32();
2127 int rval = right.toInt32();
2128 return Encode((int)(lval & rval));
2129}
2130
2131ReturnedValue Runtime::BitOr::call(const Value &left, const Value &right)
2132{
2133 TRACE2(left, right);
2134
2135 int lval = left.toInt32();
2136 int rval = right.toInt32();
2137 return Encode((int)(lval | rval));
2138}
2139
2140ReturnedValue Runtime::BitXor::call(const Value &left, const Value &right)
2141{
2142 TRACE2(left, right);
2143
2144 int lval = left.toInt32();
2145 int rval = right.toInt32();
2146 return Encode((int)(lval ^ rval));
2147}
2148
2149ReturnedValue Runtime::Shl::call(const Value &left, const Value &right)
2150{
2151 TRACE2(left, right);
2152
2153 int lval = left.toInt32();
2154 int rval = right.toInt32() & 0x1f;
2155 return Encode((int)(lval << rval));
2156}
2157
2158ReturnedValue Runtime::Shr::call(const Value &left, const Value &right)
2159{
2160 TRACE2(left, right);
2161
2162 int lval = left.toInt32();
2163 unsigned rval = right.toUInt32() & 0x1f;
2164 return Encode((int)(lval >> rval));
2165}
2166
2167ReturnedValue Runtime::UShr::call(const Value &left, const Value &right)
2168{
2169 TRACE2(left, right);
2170
2171 unsigned lval = left.toUInt32();
2172 unsigned rval = right.toUInt32() & 0x1f;
2173 uint res = lval >> rval;
2174
2175 return Encode(res);
2176}
2177
2178ReturnedValue Runtime::GreaterThan::call(const Value &left, const Value &right)
2179{
2180 TRACE2(left, right);
2181
2182 bool r = CompareGreaterThan::call(left, right);
2183 return Encode(r);
2184}
2185
2186ReturnedValue Runtime::LessThan::call(const Value &left, const Value &right)
2187{
2188 TRACE2(left, right);
2189
2190 bool r = CompareLessThan::call(left, right);
2191 return Encode(r);
2192}
2193
2194ReturnedValue Runtime::GreaterEqual::call(const Value &left, const Value &right)
2195{
2196 TRACE2(left, right);
2197
2198 bool r = CompareGreaterEqual::call(left, right);
2199 return Encode(r);
2200}
2201
2202ReturnedValue Runtime::LessEqual::call(const Value &left, const Value &right)
2203{
2204 TRACE2(left, right);
2205
2206 bool r = CompareLessEqual::call(left, right);
2207 return Encode(r);
2208}
2209
2211{
2213 Value *stackMark = nullptr;
2215 if (engine)
2216 engine->jsStackTop = stackMark;
2217 }
2218 template <typename T>
2219 void set(Value **scopedValue, T value, ExecutionEngine *e) {
2220 if (!engine) {
2221 engine = e;
2222 stackMark = engine->jsStackTop;
2223 }
2224 if (!*scopedValue)
2225 *scopedValue = e->jsAlloca(1);
2226 **scopedValue = value;
2227 }
2228};
2229
2230Bool Runtime::CompareEqual::call(const Value &left, const Value &right)
2231{
2232 TRACE2(left, right);
2233
2234 Value lhs = left;
2235 Value rhs = right;
2236
2237 LazyScope scope;
2238 Value *lhsGuard = nullptr;
2239 Value *rhsGuard = nullptr;
2240
2241 redo:
2242 if (lhs.asReturnedValue() == rhs.asReturnedValue())
2243 return !lhs.isNaN();
2244
2245 quint32 lt = lhs.quickType();
2246 quint32 rt = rhs.quickType();
2247
2248 // LHS: Check if managed
2249 if ((lt & (Value::ManagedMask >> Value::Tag_Shift)) == 0) {
2250 if (lhs.isUndefined())
2251 return rhs.isNullOrUndefined();
2252
2253 // RHS: Check if managed
2254 if ((rt & (Value::ManagedMask >> Value::Tag_Shift)) == 0) {
2255 if (rhs.isUndefined())
2256 return false;
2257
2258 Heap::Base *l = lhs.m();
2259 Heap::Base *r = rhs.m();
2260 Q_ASSERT(l);
2261 Q_ASSERT(r);
2262 if (l->internalClass->vtable->isStringOrSymbol == r->internalClass->vtable->isStringOrSymbol)
2263 return static_cast<QV4::Managed &>(lhs).isEqualTo(&static_cast<QV4::Managed &>(rhs));
2264 if (l->internalClass->vtable->isStringOrSymbol) {
2265 scope.set(&rhsGuard, RuntimeHelpers::objectDefaultValue(&static_cast<QV4::Object &>(rhs), PREFERREDTYPE_HINT), r->internalClass->engine);
2266 rhs = rhsGuard->asReturnedValue();
2267 goto redo;
2268 } else {
2269 Q_ASSERT(r->internalClass->vtable->isStringOrSymbol);
2270 scope.set(&lhsGuard, RuntimeHelpers::objectDefaultValue(&static_cast<QV4::Object &>(lhs), PREFERREDTYPE_HINT), l->internalClass->engine);
2271 lhs = lhsGuard->asReturnedValue();
2272 goto redo;
2273 }
2274 return false;
2275 }
2276
2277lhs_managed_and_rhs_not:
2278 switch (rt) {
2280 Q_UNREACHABLE();
2282 return false;
2284 case QV4::Value::QT_Int:
2285 rhs = Value::fromDouble(rhs.int_32());
2286 Q_FALLTHROUGH();
2287 default: // double
2288 if (lhs.m()->internalClass->vtable->isStringOrSymbol) {
2289 return lhs.m()->internalClass->vtable->isString ? (RuntimeHelpers::toNumber(lhs) == rhs.doubleValue()) : false;
2290 } else {
2291 scope.set(&lhsGuard, RuntimeHelpers::objectDefaultValue(&static_cast<QV4::Object &>(lhs), PREFERREDTYPE_HINT), lhs.m()->internalClass->engine);
2292 lhs = lhsGuard->asReturnedValue();
2293 }
2294 }
2295 goto redo;
2296 } else if ((rt & (Value::ManagedMask >> Value::Tag_Shift)) == 0) {
2297 if (rhs.isUndefined())
2298 return lhs.isNull(); // Can't be undefined
2299 qSwap(lhs, rhs);
2300 qSwap(lt, rt);
2301 goto lhs_managed_and_rhs_not;
2302 }
2303
2304 switch (lt) {
2306 Q_UNREACHABLE();
2308 return rhs.isNull();
2310 case QV4::Value::QT_Int:
2311 switch (rt) {
2313 Q_UNREACHABLE();
2315 return false;
2317 case QV4::Value::QT_Int:
2318 return lhs.int_32() == rhs.int_32();
2319 default: // double
2320 return lhs.int_32() == rhs.doubleValue();
2321 }
2322 default: // double
2323 switch (rt) {
2325 Q_UNREACHABLE();
2327 return false;
2329 case QV4::Value::QT_Int:
2330 return lhs.doubleValue() == rhs.int_32();
2331 default: // double
2332 return lhs.doubleValue() == rhs.doubleValue();
2333 }
2334 }
2335}
2336
2337ReturnedValue Runtime::Equal::call(const Value &left, const Value &right)
2338{
2339 TRACE2(left, right);
2340
2341 bool r = CompareEqual::call(left, right);
2342 return Encode(r);
2343}
2344
2345ReturnedValue Runtime::NotEqual::call(const Value &left, const Value &right)
2346{
2347 TRACE2(left, right);
2348
2349 bool r = !CompareEqual::call(left, right);
2350 return Encode(r);
2351}
2352
2353ReturnedValue Runtime::StrictEqual::call(const Value &left, const Value &right)
2354{
2355 TRACE2(left, right);
2356
2357 bool r = RuntimeHelpers::strictEqual(left, right);
2358 return Encode(r);
2359}
2360
2361ReturnedValue Runtime::StrictNotEqual::call(const Value &left, const Value &right)
2362{
2363 TRACE2(left, right);
2364
2365 bool r = ! RuntimeHelpers::strictEqual(left, right);
2366 return Encode(r);
2367}
2368
2369Bool Runtime::CompareNotEqual::call(const Value &left, const Value &right)
2370{
2371 TRACE2(left, right);
2372
2373 return !Runtime::CompareEqual::call(left, right);
2374}
2375
2376Bool Runtime::CompareStrictEqual::call(const Value &left, const Value &right)
2377{
2378 TRACE2(left, right);
2379
2380 return RuntimeHelpers::strictEqual(left, right);
2381}
2382
2383Bool Runtime::CompareStrictNotEqual::call(const Value &left, const Value &right)
2384{
2385 TRACE2(left, right);
2386
2387 return ! RuntimeHelpers::strictEqual(left, right);
2388}
2389
2390template<typename Operation>
2391static inline const void *symbol()
2392{
2393 return reinterpret_cast<void *>(&Operation::call);
2394}
2395
2397{
2398 static const QHash<const void *, const char *> symbols({
2399#ifndef V4_BOOTSTRAP
2400 {symbol<CallGlobalLookup>(), "CallGlobalLookup" },
2401 {symbol<CallQmlContextPropertyLookup>(), "CallQmlContextPropertyLookup" },
2402 {symbol<CallName>(), "CallName" },
2403 {symbol<CallProperty>(), "CallProperty" },
2404 {symbol<CallPropertyLookup>(), "CallPropertyLookup" },
2405 {symbol<CallValue>(), "CallValue" },
2406 {symbol<CallWithReceiver>(), "CallWithReceiver" },
2407 {symbol<CallPossiblyDirectEval>(), "CallPossiblyDirectEval" },
2408 {symbol<CallWithSpread>(), "CallWithSpread" },
2409 {symbol<TailCall>(), "TailCall" },
2410
2411 {symbol<Construct>(), "Construct" },
2412 {symbol<ConstructWithSpread>(), "ConstructWithSpread" },
2413
2414 {symbol<StoreNameStrict>(), "StoreNameStrict" },
2415 {symbol<StoreNameSloppy>(), "StoreNameSloppy" },
2416 {symbol<StoreProperty>(), "StoreProperty" },
2417 {symbol<StoreElement>(), "StoreElement" },
2418 {symbol<LoadProperty>(), "LoadProperty" },
2419 {symbol<LoadName>(), "LoadName" },
2420 {symbol<LoadElement>(), "LoadElement" },
2421 {symbol<LoadSuperProperty>(), "LoadSuperProperty" },
2422 {symbol<StoreSuperProperty>(), "StoreSuperProperty" },
2423 {symbol<LoadSuperConstructor>(), "LoadSuperConstructor" },
2424 {symbol<LoadGlobalLookup>(), "LoadGlobalLookup" },
2425 {symbol<LoadQmlContextPropertyLookup>(), "LoadQmlContextPropertyLookup" },
2426 {symbol<GetLookup>(), "GetLookup" },
2427 {symbol<SetLookupStrict>(), "SetLookupStrict" },
2428 {symbol<SetLookupSloppy>(), "SetLookupSloppy" },
2429
2430 {symbol<TypeofValue>(), "TypeofValue" },
2431 {symbol<TypeofName>(), "TypeofName" },
2432
2433 {symbol<DeleteProperty_NoThrow>(), "DeleteProperty_NoThrow" },
2434 {symbol<DeleteProperty>(), "DeleteProperty" },
2435 {symbol<DeleteName_NoThrow>(), "DeleteName_NoThrow" },
2436 {symbol<DeleteName>(), "DeleteName" },
2437
2438 {symbol<ThrowException>(), "ThrowException" },
2439 {symbol<PushCallContext>(), "PushCallContext" },
2440 {symbol<PushWithContext>(), "PushWithContext" },
2441 {symbol<PushCatchContext>(), "PushCatchContext" },
2442 {symbol<PushBlockContext>(), "PushBlockContext" },
2443 {symbol<CloneBlockContext>(), "CloneBlockContext" },
2444 {symbol<PushScriptContext>(), "PushScriptContext" },
2445 {symbol<PopScriptContext>(), "PopScriptContext" },
2446 {symbol<ThrowReferenceError>(), "ThrowReferenceError" },
2447 {symbol<ThrowOnNullOrUndefined>(), "ThrowOnNullOrUndefined" },
2448
2449 {symbol<Closure>(), "Closure" },
2450
2451 {symbol<ConvertThisToObject>(), "ConvertThisToObject" },
2452 {symbol<DeclareVar>(), "DeclareVar" },
2453 {symbol<CreateMappedArgumentsObject>(), "CreateMappedArgumentsObject" },
2454 {symbol<CreateUnmappedArgumentsObject>(), "CreateUnmappedArgumentsObject" },
2455 {symbol<CreateRestParameter>(), "CreateRestParameter" },
2456
2457 {symbol<ArrayLiteral>(), "ArrayLiteral" },
2458 {symbol<ObjectLiteral>(), "ObjectLiteral" },
2459 {symbol<CreateClass>(), "CreateClass" },
2460
2461 {symbol<GetIterator>(), "GetIterator" },
2462 {symbol<IteratorNext>(), "IteratorNext" },
2463 {symbol<IteratorNextForYieldStar>(), "IteratorNextForYieldStar" },
2464 {symbol<IteratorClose>(), "IteratorClose" },
2465 {symbol<DestructureRestElement>(), "DestructureRestElement" },
2466
2467 {symbol<ToObject>(), "ToObject" },
2468 {symbol<ToBoolean>(), "ToBoolean" },
2469 {symbol<ToNumber>(), "ToNumber" },
2470
2471 {symbol<UMinus>(), "UMinus" },
2472
2473 {symbol<Instanceof>(), "Instanceof" },
2474 {symbol<As>(), "As" },
2475 {symbol<In>(), "In" },
2476 {symbol<Add>(), "Add" },
2477 {symbol<Sub>(), "Sub" },
2478 {symbol<Mul>(), "Mul" },
2479 {symbol<Div>(), "Div" },
2480 {symbol<Mod>(), "Mod" },
2481 {symbol<Exp>(), "Exp" },
2482 {symbol<BitAnd>(), "BitAnd" },
2483 {symbol<BitOr>(), "BitOr" },
2484 {symbol<BitXor>(), "BitXor" },
2485 {symbol<Shl>(), "Shl" },
2486 {symbol<Shr>(), "Shr" },
2487 {symbol<UShr>(), "UShr" },
2488 {symbol<GreaterThan>(), "GreaterThan" },
2489 {symbol<LessThan>(), "LessThan" },
2490 {symbol<GreaterEqual>(), "GreaterEqual" },
2491 {symbol<LessEqual>(), "LessEqual" },
2492 {symbol<Equal>(), "Equal" },
2493 {symbol<NotEqual>(), "NotEqual" },
2494 {symbol<StrictEqual>(), "StrictEqual" },
2495 {symbol<StrictNotEqual>(), "StrictNotEqual" },
2496
2497 {symbol<CompareGreaterThan>(), "CompareGreaterThan" },
2498 {symbol<CompareLessThan>(), "CompareLessThan" },
2499 {symbol<CompareGreaterEqual>(), "CompareGreaterEqual" },
2500 {symbol<CompareLessEqual>(), "CompareLessEqual" },
2501 {symbol<CompareEqual>(), "CompareEqual" },
2502 {symbol<CompareNotEqual>(), "CompareNotEqual" },
2503 {symbol<CompareStrictEqual>(), "CompareStrictEqual" },
2504 {symbol<CompareStrictNotEqual>(), "CompareStrictNotEqual" },
2505
2506 {symbol<CompareInstanceof>(), "CompareInstanceOf" },
2507 {symbol<CompareIn>(), "CompareIn" },
2508
2509 {symbol<RegexpLiteral>(), "RegexpLiteral" },
2510 {symbol<GetTemplateObject>(), "GetTemplateObject" }
2511#endif
2512 });
2513
2514 return symbols;
2515}
2516
2517} // namespace QV4
2518
static JNINativeMethod methods[]
\inmodule QtCore \reentrant
Definition qbuffer.h:16
\inmodule QtCore
Definition qbytearray.h:57
qsizetype size() const noexcept
Returns the number of bytes in this byte array.
Definition qbytearray.h:474
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
Definition qbytearray.h:122
\inmodule QtCore
Definition qhash.h:818
void throwError(const QString &message)
Throws a run-time error (exception) with the given message.
QJSValue globalObject() const
Returns this engine's Global Object.
QJSValue newObject()
Creates a JavaScript object of class Object.
Definition qlist.h:74
qsizetype size() const noexcept
Definition qlist.h:386
bool isEmpty() const noexcept
Definition qlist.h:390
iterator end()
Definition qlist.h:609
iterator begin()
Definition qlist.h:608
void resize(qsizetype size)
Definition qlist.h:392
void append(parameter_type t)
Definition qlist.h:441
bool setProperty(const char *name, const QVariant &value)
Sets the value of the object's name property to value.
const_iterator cbegin() const noexcept
Definition qset.h:138
\inmodule QtCore
Definition qstringview.h:76
QStringView trimmed() const noexcept
Strips leading and trailing whitespace and returns the result.
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
qsizetype size() const
Returns the number of characters in this string.
Definition qstring.h:182
QString mid(qsizetype position, qsizetype n=-1) const
Returns a string that contains n characters of this string, starting at the specified position index.
Definition qstring.cpp:5204
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:1083
qsizetype count(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition qstring.cpp:4732
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:7822
\inmodule QtCore
ManagedType::Data * alloc(Args &&... args)
Definition qv4mm_p.h:208
EGLContext ctx
QString str
[2]
qSwap(pi, e)
double e
QSet< QString >::iterator it
QList< QVariant > arguments
short next
Definition keywords.cpp:445
double jsExponentiate(double base, double exponent)
Combined button and popup list for selecting options.
\qmltype Particle \inqmlmodule QtQuick.Particles
static QV4::ReturnedValue doInstanceof(ExecutionEngine *engine, const Value &lval, const Value &rval)
static Q_NEVER_INLINE ReturnedValue getElementIntFallback(ExecutionEngine *engine, const Value &object, uint idx)
@ STRING_HINT
@ PREFERREDTYPE_HINT
@ NUMBER_HINT
static Q_NEVER_INLINE ReturnedValue getElementFallback(ExecutionEngine *engine, const Value &object, const Value &index)
ReturnedValue coerce(ExecutionEngine *engine, const Value &value, const QQmlType &qmlType, bool isList)
quint64 ReturnedValue
static Heap::String * convert_to_string_add(ExecutionEngine *engine, Value value)
uint Bool
static ReturnedValue throwPropertyIsNotAFunctionTypeError(ExecutionEngine *engine, Value *thisObject, const QString &propertyName)
ReturnedValue checkedResult(QV4::ExecutionEngine *v4, ReturnedValue result)
static QV4::Lookup * runtimeLookup(Function *f, uint i)
static Q_NEVER_INLINE bool setElementFallback(ExecutionEngine *engine, const Value &object, const Value &index, const Value &value)
@ Attr_Data
@ Attr_NotEnumerable
@ Attr_Accessor
static Object * getSuperBase(Scope &scope)
static CallArgs createSpreadArguments(Scope &scope, Value *argv, int argc)
static const void * symbol()
QTextStream & endl(QTextStream &stream)
Writes '\n' to the stream and flushes the stream.
static void * context
#define Q_FALLTHROUGH()
#define Q_NEVER_INLINE
#define Q_LIKELY(x)
AudioChannelLayoutTag tag
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction function
DBusConnection const char DBusError * error
static QDBusError::ErrorType get(const char *name)
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
QString qdtoa(qreal d, int *decpt, int *sign)
double qstrtod(const char *s00, char const **se, bool *ok)
#define qDebug
[1]
Definition qlogging.h:160
return ret
#define Q_INFINITY
Definition qnumeric.h:77
Q_CORE_EXPORT Q_DECL_CONST_FUNCTION double qQNaN()
static Q_DECL_CONST_FUNCTION bool qt_is_inf(double d)
Definition qnumeric_p.h:101
GLenum GLsizei GLsizei GLint * values
[15]
GLboolean GLboolean GLboolean b
GLsizei const GLfloat * v
[13]
GLint GLint GLint GLint GLint x
[0]
const GLfloat * m
GLuint64 key
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint index
[2]
GLboolean r
[2]
GLuint GLuint end
GLenum GLuint GLenum GLsizei length
GLenum GLuint id
[7]
GLenum GLenum GLsizei count
GLuint object
[3]
GLdouble GLdouble right
GLfloat GLfloat f
GLint left
GLenum type
GLint GLint GLsizei GLuint * counters
GLenum GLuint GLenum GLsizei const GLchar * buf
GLuint GLsizei const GLchar * message
GLuint name
GLfloat n
GLint y
GLhandleARB obj
[2]
GLenum func
Definition qopenglext.h:663
GLuint res
const GLubyte * c
GLuint GLfloat * val
GLenum array
GLdouble GLdouble t
Definition qopenglext.h:243
GLuint in
GLuint64EXT * result
[6]
GLdouble s
[6]
Definition qopenglext.h:235
GLuint num
static qreal dot(const QPointF &a, const QPointF &b)
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIterator begin(const QRegularExpressionMatchIterator &iterator)
static QString dump(const QByteArray &)
SSL_CTX int(*) void arg)
QLatin1StringView QLatin1String
Definition qstringfwd.h:31
#define QStringLiteral(str)
static QT_BEGIN_NAMESPACE QVariant hint(QPlatformIntegration::StyleHint h)
#define zero
QTextStreamManipulator qSetFieldWidth(int width)
unsigned int quint32
Definition qtypes.h:45
unsigned long long quint64
Definition qtypes.h:56
unsigned int uint
Definition qtypes.h:29
long long qint64
Definition qtypes.h:55
qint64 qlonglong
Definition qtypes.h:58
#define TRACE1(x)
#define TRACE2(x, y)
static int sign(int x)
const char property[13]
Definition qwizard.cpp:101
QByteArray ba
[0]
QFrame frame
[0]
QJSValueList args
QJSEngine engine
[0]
\inmodule QtCore \reentrant
Definition qchar.h:17
StaticValue accumulator
StaticValue context
const Method * methodTable() const
const Class * classAt(int idx) const
bool isJSTypesFrame() const
bool isMetaTypesFrame() const
CppStackFrame * currentStackFrame
CallContext * asCallContext()
Heap::String * newString(const QString &s=QString())
ReturnedValue throwRangeError(const Value &value)
String * id_length() const
ReturnedValue throwReferenceError(const Value &value)
String * id_prototype() const
ReturnedValue throwTypeError()
ExecutionContext * currentContext() const
CompiledData::CompilationUnitBase * compilationUnit
unsigned int formalParameterCount() const
ReturnedValue call(const JSCallData &data) const
Function * function() const
Heap::ExecutionContext * scope() const
bool isStrict() const
bool isArrowFunction() const
bool isGenerator() const
ReturnedValue asReturnedValue() const
Definition qv4value_p.h:339
Pointer< InternalClass *, 0 > internalClass
Definition qv4heap_p.h:63
void setData(EngineBase *e, uint index, Value newVal)
const Value & data(uint index) const
ExecutionContext * context() const
void set(Value **scopedValue, T value, ExecutionEngine *e)
ReturnedValue(* globalGetter)(Lookup *l, ExecutionEngine *engine)
Definition qv4lookup_p.h:37
ReturnedValue(* qmlContextPropertyGetter)(Lookup *l, ExecutionEngine *engine, Value *thisObject)
Definition qv4lookup_p.h:38
ReturnedValue(* getter)(Lookup *l, ExecutionEngine *engine, const Value &object)
Definition qv4lookup_p.h:36
bool(* setter)(Lookup *l, ExecutionEngine *engine, Value &object, const Value &v)
Definition qv4lookup_p.h:39
ExecutionEngine * engine() const
bool hasProperty(PropertyKey id) const
ReturnedValue instanceOf(const Value &var) const
ReturnedValue get(StringOrSymbol *name, bool *hasProperty=nullptr, const Value *receiver=nullptr) const
Heap::String * asFunctionName(ExecutionEngine *e, FunctionNamePrefix prefix) const
Value * alloc(qint64 nValues) const =delete
bool hasException() const
ExecutionEngine * engine
QML_NEARLY_ALWAYS_INLINE ReturnedValue asReturnedValue() const
bool isNumber() const
quint64 quickType() const
const Value & asValue() const
bool isInteger() const
constexpr ReturnedValue asReturnedValue() const
QV4_NEARLY_ALWAYS_INLINE double doubleValue() const
bool isNullOrUndefined() const
int integerValue() const
bool isUndefined() const
QV4_NEARLY_ALWAYS_INLINE constexpr int int_32() const
double asDouble() const
PropertyKey propertyKey() const
bool lessThan(const String *other)
bool isStringOrSymbol() const
Definition qv4value_p.h:290
bool isString() const
Definition qv4value_p.h:284
QV4::PropertyKey toPropertyKey(ExecutionEngine *e) const
Definition qv4value.cpp:207
QML_NEARLY_ALWAYS_INLINE String * stringValue() const
Definition qv4value_p.h:55
double toNumber() const
Definition qv4value_p.h:320
QML_NEARLY_ALWAYS_INLINE Object * objectValue() const
Definition qv4value_p.h:70
const T * as() const
Definition qv4value_p.h:132
QString toQStringNoThrow() const
Definition qv4value.cpp:122
Heap::Object * toObject(ExecutionEngine *e) const
Definition qv4value_p.h:122
bool isObject() const
Definition qv4value_p.h:302
Definition moc.h:24
void wrapper()