Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qv4functionobject.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 "qv4object_p.h"
5#include "qv4function_p.h"
6#include "qv4symbol_p.h"
7#include <private/qv4mm_p.h>
8
9#include "qv4scopedvalue_p.h"
11
12#include <private/qqmljsengine_p.h>
13#include <private/qqmljslexer_p.h>
14#include <private/qqmljsparser_p.h>
15#include <private/qqmljsast_p.h>
16#include <private/qqmljavascriptexpression_p.h>
17#include <private/qqmlengine_p.h>
18#include <qv4runtimecodegen_p.h>
19#include "private/qlocale_tools_p.h"
20#include "private/qqmlbuiltinfunctions_p.h"
21#include <private/qv4jscall_p.h>
22#include <private/qv4vme_moth_p.h>
23#include <private/qv4alloca_p.h>
24
25#include <QtCore/QDebug>
26#include <algorithm>
27
28using namespace QV4;
29
30
32
33void Heap::FunctionObject::init(QV4::ExecutionContext *scope, QV4::String *name,
34 VTable::Call call, VTable::CallWithMetaTypes callWithMetaTypes)
35{
36 jsCall = call;
37 jsCallWithMetaTypes = callWithMetaTypes;
38 jsConstruct = nullptr;
39
40 Object::init();
41 this->scope.set(scope->engine(), scope->d());
42 Scope s(scope->engine());
44 if (name)
45 f->setName(name);
46}
47
48void Heap::FunctionObject::init(QV4::ExecutionContext *scope, QV4::String *name)
49{
50 ExecutionEngine *e = scope->engine();
51
52 jsCall = vtable()->call;
53 jsCallWithMetaTypes = vtable()->callWithMetaTypes;
54 jsConstruct = vtable()->callAsConstructor;
55
56 Object::init();
57 this->scope.set(scope->engine(), scope->d());
58 Scope s(e);
60 if (name)
61 f->setName(name);
62}
63
64
65
66void Heap::FunctionObject::init(QV4::ExecutionContext *scope, Function *function, QV4::String *n)
67{
68 jsCall = vtable()->call;
69 jsCallWithMetaTypes = vtable()->callWithMetaTypes;
70 jsConstruct = vtable()->callAsConstructor;
71
72 Object::init();
73 setFunction(function);
74 this->scope.set(scope->engine(), scope->d());
75 Scope s(scope->engine());
76 ScopedString name(s, n ? n->d() : function->name());
78 if (name)
79 f->setName(name);
80}
81
82void Heap::FunctionObject::init(QV4::ExecutionContext *scope, const QString &name)
83{
84 Scope valueScope(scope);
85 ScopedString s(valueScope, valueScope.engine->newString(name));
86 init(scope, s);
87}
88
89void Heap::FunctionObject::init()
90{
91 jsCall = vtable()->call;
92 jsCallWithMetaTypes = vtable()->callWithMetaTypes;
93 jsConstruct = vtable()->callAsConstructor;
94
95 Object::init();
96 this->scope.set(internalClass->engine, internalClass->engine->rootContext()->d());
97}
98
99void Heap::FunctionObject::setFunction(Function *f)
100{
101 if (f) {
102 function = f;
103 function->executableCompilationUnit()->addref();
104 }
105}
106void Heap::FunctionObject::destroy()
107{
108 if (function)
109 function->executableCompilationUnit()->release();
110 Object::destroy();
111}
112
114{
115 Scope s(this);
116
117 Q_ASSERT(s.engine->internalClasses(EngineBase::Class_ObjectProto)->verifyIndex(s.engine->id_constructor()->propertyKey(), protoConstructorSlot));
118
119 ScopedObject proto(s, s.engine->newObject(s.engine->internalClasses(EngineBase::Class_ObjectProto)));
120 proto->setProperty(protoConstructorSlot, d());
121 defineDefaultProperty(s.engine->id_prototype(), proto, Attr_NotEnumerable|Attr_NotConfigurable);
122}
123
124void FunctionObject::call(QObject *thisObject, void **a, const QMetaType *types, int argc)
125{
126 if (const auto callWithMetaTypes = d()->jsCallWithMetaTypes) {
127 callWithMetaTypes(this, thisObject, a, types, argc);
128 return;
129 }
130
131 QV4::convertAndCall(engine(), thisObject, a, types, argc,
132 [this](const Value *thisObject, const Value *argv, int argc) {
133 return call(thisObject, argv, argc);
134 });
135}
136
138{
139 return get(scope()->internalClass->engine->id_name());
140}
141
143{
144 return Encode::undefined();
145}
146
148 const FunctionObject *, QObject *, void **, const QMetaType *, int)
149{
150}
151
152Heap::FunctionObject *FunctionObject::createScriptFunction(ExecutionContext *scope, Function *function)
153{
155 return scope->engine()->memoryManager->allocate<ArrowFunction>(scope, function);
156 return scope->engine()->memoryManager->allocate<ScriptFunction>(scope, function);
157}
158
159Heap::FunctionObject *FunctionObject::createConstructorFunction(ExecutionContext *scope, Function *function, Object *homeObject, bool isDerivedConstructor)
160{
161 if (!function) {
163 c->isDerivedConstructor = isDerivedConstructor;
164 return c;
165 }
166 Heap::ConstructorFunction *c = scope->engine()->memoryManager->allocate<ConstructorFunction>(scope, function);
167 c->homeObject.set(scope->engine(), homeObject->d());
168 c->isDerivedConstructor = isDerivedConstructor;
169 return c;
170}
171
172Heap::FunctionObject *FunctionObject::createMemberFunction(ExecutionContext *scope, Function *function, Object *homeObject, QV4::String *name)
173{
174 Heap::MemberFunction *m = scope->engine()->memoryManager->allocate<MemberFunction>(scope, function, name);
175 m->homeObject.set(scope->engine(), homeObject->d());
176 return m;
177}
178
179Heap::FunctionObject *FunctionObject::createBuiltinFunction(ExecutionEngine *engine, StringOrSymbol *nameOrSymbol, VTable::Call code, int argumentCount)
180{
182 ScopedString name(scope, nameOrSymbol);
183 if (!name)
184 name = engine->newString(QChar::fromLatin1('[') + QStringView{nameOrSymbol->toQString()}.mid(1) + QChar::fromLatin1(']'));
185
187 function->defineReadonlyConfigurableProperty(engine->id_length(), Value::fromInt32(argumentCount));
188 return function->d();
189}
190
192{
193 const MemberFunction *m = as<MemberFunction>();
194 if (m)
195 return m->d()->homeObject->asReturnedValue();
196 const ConstructorFunction *c = as<ConstructorFunction>();
197 if (c)
198 return c->d()->homeObject->asReturnedValue();
199 return Encode::undefined();
200}
201
203{
204 return d()->function->sourceLocation();
205}
206
208
210{
211 Heap::FunctionObject::init(scope, QStringLiteral("Function"));
212}
213
214// 15.3.2
216{
218 QString body;
219 if (argc > 0) {
220 for (int i = 0, ei = argc - 1; i < ei; ++i) {
221 if (i)
222 arguments += QLatin1String(", ");
223 arguments += argv[i].toQString();
224 }
225 body = argv[argc - 1].toQString();
226 }
227 if (engine->hasException)
228 return nullptr;
229
230 QString function = (t == Type_Function ? QLatin1String("function anonymous(") : QLatin1String("function* anonymous(")) + arguments + QLatin1String("\n){") + body + QLatin1String("\n}");
231
233 QQmlJS::Lexer lexer(&ee);
234 lexer.setCode(function, 1, false);
235 QQmlJS::Parser parser(&ee);
236
237 const bool parsed = parser.parseExpression();
238
239 if (!parsed) {
240 engine->throwSyntaxError(QLatin1String("Parse error"));
241 return nullptr;
242 }
243
244 QQmlJS::AST::FunctionExpression *fe = QQmlJS::AST::cast<QQmlJS::AST::FunctionExpression *>(parser.rootNode());
245 if (!fe) {
246 engine->throwSyntaxError(QLatin1String("Parse error"));
247 return nullptr;
248 }
249
250 Compiler::Module module(engine->debugger() != nullptr);
251
252 Compiler::JSUnitGenerator jsGenerator(&module);
253 RuntimeCodegen cg(engine, &jsGenerator, false);
255
256 if (engine->hasException)
257 return nullptr;
258
260}
261
262ReturnedValue FunctionCtor::virtualCallAsConstructor(const FunctionObject *f, const Value *argv, int argc, const Value *newTarget)
263{
264 ExecutionEngine *engine = f->engine();
265
267 = parse(engine, argv, argc, Type_Function);
268 if (engine->hasException)
269 return Encode::undefined();
270
271 Function *vmf = compilationUnit->linkToEngine(engine);
274
275 if (!newTarget)
276 return o;
279 obj->setProtoFromNewTarget(newTarget);
280 return obj->asReturnedValue();
281}
282
283// 15.3.1: This is equivalent to new Function(...)
284ReturnedValue FunctionCtor::virtualCall(const FunctionObject *f, const Value *, const Value *argv, int argc)
285{
286 return virtualCallAsConstructor(f, argv, argc, f);
287}
288
290
292{
293 Heap::FunctionObject::init();
294}
295
297{
300
302 ctor->defineReadonlyProperty(engine->id_prototype(), (o = this));
303
306 defineDefaultProperty(QStringLiteral("constructor"), (o = ctor));
307 defineDefaultProperty(engine->id_toString(), method_toString, 0);
308 defineDefaultProperty(QStringLiteral("apply"), method_apply, 2);
309 defineDefaultProperty(QStringLiteral("call"), method_call, 1);
310 defineDefaultProperty(QStringLiteral("bind"), method_bind, 1);
312}
313
315{
316 ExecutionEngine *v4 = b->engine();
317 const FunctionObject *fun = thisObject->as<FunctionObject>();
318 if (!fun)
319 return v4->throwTypeError();
320
321 const Scope scope(fun->engine());
322 const ScopedString scopedFunctionName(scope, fun->name());
323 const QString functionName(scopedFunctionName ? scopedFunctionName->toQString() : QString());
324 QString functionAsString = QStringLiteral("function");
325
326 // If fun->name() is empty, then there is no function name
327 // to append because the function is anonymous.
328 if (!functionName.isEmpty())
329 functionAsString.append(QLatin1Char(' ') + functionName);
330
331 functionAsString.append(QStringLiteral("() { [native code] }"));
332
333 return Encode(v4->newString(functionAsString));
334}
335
336ReturnedValue FunctionPrototype::method_apply(const QV4::FunctionObject *b, const Value *thisObject, const Value *argv, int argc)
337{
338 ExecutionEngine *v4 = b->engine();
339 const FunctionObject *f = thisObject->as<FunctionObject>();
340 if (!f)
341 return v4->throwTypeError();
342 thisObject = argc ? argv : nullptr;
343 if (argc < 2 || argv[1].isNullOrUndefined())
344 return checkedResult(v4, f->call(thisObject, argv, 0));
345
346 Object *arr = argv[1].objectValue();
347 if (!arr)
348 return v4->throwTypeError();
349
350 Scope scope(v4);
351 const int len = v4->safeForAllocLength(arr->getLength());
353
355 if (len) {
356 if (ArgumentsObject::isNonStrictArgumentsObject(arr) && !arr->cast<ArgumentsObject>()->fullyCreated()) {
358 int l = qMin(len, a->d()->context->argc());
359 memcpy(arguments, a->d()->context->args(), l*sizeof(Value));
360 for (int i = l; i < len; ++i)
362 } else if (arr->arrayType() == Heap::ArrayData::Simple && !arr->protoHasArray()) {
363 auto sad = static_cast<Heap::SimpleArrayData *>(arr->arrayData());
364 int alen = sad ? sad->values.size : 0;
365 if (alen > len)
366 alen = len;
367 for (int i = 0; i < alen; ++i)
368 arguments[i] = sad->data(i);
369 for (int i = alen; i < len; ++i)
371 } else {
372 // need to init the arguments array, as the get() calls below can have side effects
373 memset(arguments, 0, len*sizeof(Value));
374 for (int i = 0; i < len; ++i)
375 arguments[i] = arr->get(i);
376 }
377 }
378
379 return checkedResult(v4, f->call(thisObject, arguments, len));
380}
381
382ReturnedValue FunctionPrototype::method_call(const QV4::FunctionObject *b, const Value *thisObject, const Value *argv, int argc)
383{
384 QV4::ExecutionEngine *v4 = b->engine();
385 if (!thisObject->isFunctionObject())
386 return v4->throwTypeError();
387
388 const FunctionObject *f = static_cast<const FunctionObject *>(thisObject);
389
390 thisObject = argc ? argv : nullptr;
391 if (argc) {
392 ++argv;
393 --argc;
394 }
395 return checkedResult(v4, f->call(thisObject, argv, argc));
396}
397
398ReturnedValue FunctionPrototype::method_bind(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc)
399{
401 ScopedFunctionObject target(scope, thisObject);
402 if (!target || target->isBinding())
403 return scope.engine->throwTypeError();
404
405 ScopedValue boundThis(scope, argc ? argv[0] : Value::undefinedValue());
406 Scoped<MemberData> boundArgs(scope, (Heap::MemberData *)nullptr);
407
408 int nArgs = (argc - 1 >= 0) ? argc - 1 : 0;
409 if (target->isBoundFunction()) {
410 BoundFunction *bound = static_cast<BoundFunction *>(target.getPointer());
411 Scoped<MemberData> oldArgs(scope, bound->boundArgs());
412 boundThis = bound->boundThis();
413 int oldSize = !oldArgs ? 0 : oldArgs->size();
414 if (oldSize + nArgs) {
415 boundArgs = MemberData::allocate(scope.engine, oldSize + nArgs);
416 boundArgs->d()->values.size = oldSize + nArgs;
417 for (uint i = 0; i < static_cast<uint>(oldSize); ++i)
418 boundArgs->set(scope.engine, i, oldArgs->data()[i]);
419 for (uint i = 0; i < static_cast<uint>(nArgs); ++i)
420 boundArgs->set(scope.engine, oldSize + i, argv[i + 1]);
421 }
422 target = bound->target();
423 } else if (nArgs) {
424 boundArgs = MemberData::allocate(scope.engine, nArgs);
425 boundArgs->d()->values.size = nArgs;
426 for (uint i = 0, ei = static_cast<uint>(nArgs); i < ei; ++i)
427 boundArgs->set(scope.engine, i, argv[i + 1]);
428 }
429
430 ScopedContext ctx(scope, target->scope());
431 Heap::BoundFunction *bound = BoundFunction::create(ctx, target, boundThis, boundArgs);
432 bound->setFunction(target->function());
433 return bound->asReturnedValue();
434}
435
436ReturnedValue FunctionPrototype::method_hasInstance(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
437{
438 if (!argc)
439 return Encode(false);
440 const Object *o = thisObject->as<Object>();
441 if (!o)
442 return Encode(false);
443
444 return Object::virtualInstanceOf(o, argv[0]);
445}
446
448
449ReturnedValue ScriptFunction::virtualCallAsConstructor(const FunctionObject *fo, const Value *argv, int argc, const Value *newTarget)
450{
451 ExecutionEngine *v4 = fo->engine();
452 const ScriptFunction *f = static_cast<const ScriptFunction *>(fo);
453 Q_ASSERT(newTarget->isFunctionObject());
454 const FunctionObject *nt = static_cast<const FunctionObject *>(newTarget);
455
456 Scope scope(v4);
457 Scoped<InternalClass> ic(scope);
458 if (nt->d() == f->d()) {
459 ic = f->classForConstructor();
460 } else {
461 ScopedObject o(scope, nt->protoProperty());
463 if (o)
464 ic = ic->changePrototype(o->d());
465 }
466 ScopedValue thisObject(scope, v4->memoryManager->allocObject<Object>(ic));
467
469 frame.init(f->function(), argv, argc);
470 frame.setupJSFrame(v4->jsStackTop, *f, f->scope(),
471 thisObject,
472 newTarget ? *newTarget : Value::undefinedValue());
473
474 frame.push(v4);
475 v4->jsStackTop += frame.requiredJSStackFrameSize();
476
478
479 frame.pop(v4);
480
481 if (Q_UNLIKELY(v4->hasException))
482 return Encode::undefined();
483 else if (!Value::fromReturnedValue(result).isObject())
484 return thisObject->asReturnedValue();
485 return result;
486}
487
489
491 void **a, const QMetaType *types, int argc)
492{
493 if (fo->function()->kind != Function::AotCompiled) {
494 QV4::convertAndCall(fo->engine(), thisObject, a, types, argc,
495 [fo](const Value *thisObject, const Value *argv, int argc) {
496 return ArrowFunction::virtualCall(fo, thisObject, argv, argc);
497 });
498 return;
499 }
500
501 QV4::Scope scope(fo->engine());
504 frame.init(fo->function(), thisObject, context, a, types, argc);
505 frame.push(scope.engine);
506 Moth::VME::exec(&frame, scope.engine);
507 frame.pop(scope.engine);
508}
509
510static ReturnedValue qfoDoCall(const QV4::FunctionObject *fo, const QV4::Value *thisObject,
511 const QV4::Value *argv, int argc)
512{
515 frame.init(fo->function(), argv, argc, true);
516 frame.setupJSFrame(engine->jsStackTop, *fo, fo->scope(),
517 thisObject ? *thisObject : Value::undefinedValue());
518
519 frame.push(engine);
520 engine->jsStackTop += frame.requiredJSStackFrameSize();
521
523
524 do {
525 frame.setPendingTailCall(false);
527 frame.setTailCalling(true);
528 } while (frame.pendingTailCall());
529
530 frame.pop(engine);
531
532 return result;
533}
534
536 const QV4::Value *argv, int argc)
537{
538 Function *function = fo->function();
539 switch (function->kind) {
541 return QV4::convertAndCall(
542 fo->engine(), function->aotCompiledFunction, thisObject, argv, argc,
543 [fo](QObject *thisObject, void **a, const QMetaType *types, int argc) {
544 ArrowFunction::virtualCallWithMetaTypes(fo, thisObject, a, types, argc);
545 });
547 return QV4::coerceAndCall(
549 thisObject, argv, argc,
550 [fo](const Value *thisObject, const Value *argv, int argc) {
551 return qfoDoCall(fo, thisObject, argv, argc);
552 });
553 default:
554 break;
555 }
556
557 return qfoDoCall(fo, thisObject, argv, argc);
558}
559
561{
562 FunctionObject::init();
563 this->scope.set(scope->engine(), scope->d());
564
567
568 Scope s(scope);
569 ScopedFunctionObject f(s, this);
570
571 ScopedString name(s, n ? n->d() : function->name());
572 if (name)
573 f->setName(name);
574
575 Q_ASSERT(internalClass && internalClass->verifyIndex(s.engine->id_length()->propertyKey(), Index_Length));
576 setProperty(s.engine, Index_Length, Value::fromInt32(int(function->compiledFunction->length)));
577 canBeTailCalled = true;
578}
579
580void Heap::ScriptFunction::init(QV4::ExecutionContext *scope, Function *function)
581{
582 ArrowFunction::init(scope, function);
583 Q_ASSERT(!function->isArrowFunction());
584
585 Scope s(scope);
586 ScopedFunctionObject f(s, this);
587 f->createDefaultPrototypeProperty(Heap::FunctionObject::Index_ProtoConstructor);
588}
589
591{
592 Scope scope(engine());
593 ScopedValue o(scope, protoProperty());
594 if (d()->cachedClassForConstructor && d()->cachedClassForConstructor->prototype == o->heapObject())
595 return d()->cachedClassForConstructor;
596
597 Scoped<InternalClass> ic(scope, engine()->internalClasses(EngineBase::Class_Object));
598 ScopedObject p(scope, o);
599 if (p)
600 ic = ic->changePrototype(p->d());
601 d()->cachedClassForConstructor.set(scope.engine, ic->d());
602
603 return ic->d();
604}
605
607
609{
610 const ConstructorFunction *c = static_cast<const ConstructorFunction *>(f);
611 if (!c->d()->isDerivedConstructor)
612 return ScriptFunction::virtualCallAsConstructor(f, argv, argc, newTarget);
613
614 ExecutionEngine *v4 = f->engine();
615
617 frame.init(f->function(), argv, argc);
618 frame.setupJSFrame(v4->jsStackTop, *f, f->scope(),
620 newTarget ? *newTarget : Value::undefinedValue());
621
622 frame.push(v4);
623 v4->jsStackTop += frame.requiredJSStackFrameSize();
624
626 ReturnedValue thisObject = frame.jsFrame->thisObject.asReturnedValue();
627
628 frame.pop(v4);
629
630 if (Q_UNLIKELY(v4->hasException))
631 return Encode::undefined();
632 else if (Value::fromReturnedValue(result).isObject())
633 return result;
634 else if (!Value::fromReturnedValue(result).isUndefined())
635 return v4->throwTypeError();
636 else if (Value::fromReturnedValue(thisObject).isEmpty()) {
637 Scope scope(v4);
638 ScopedString s(scope, v4->newString(QStringLiteral("this")));
639 return v4->throwReferenceError(s);
640 }
641 return thisObject;
642}
643
645{
646 return f->engine()->throwTypeError(QStringLiteral("Cannot call a class constructor without |new|"));
647}
648
650
652
654{
656 ExecutionEngine *v4 = f->engine();
657
658 Scope scope(v4);
659
660 if (!c->d()->isDerivedConstructor) {
661 ScopedObject proto(scope, static_cast<const Object *>(newTarget)->get(scope.engine->id_prototype()));
662 ScopedObject c(scope, scope.engine->newObject());
663 c->setPrototypeUnchecked(proto);
664 return c->asReturnedValue();
665 }
666
667 ScopedFunctionObject super(scope, f->getPrototypeOf());
668 Q_ASSERT(super->isFunctionObject());
669
671 frame.init(nullptr, argv, argc);
672 frame.setupJSFrame(v4->jsStackTop, *f, f->scope(),
674 newTarget ? *newTarget : Value::undefinedValue(), argc, argc);
675
676 frame.push(v4);
677 v4->jsStackTop += frame.requiredJSStackFrameSize(argc);
678
679 // Do a super call
680 ReturnedValue result = super->callAsConstructor(argv, argc, newTarget);
681 ReturnedValue thisObject = frame.jsFrame->thisObject.asReturnedValue();
682
683 frame.pop(v4);
684
685 if (Q_UNLIKELY(v4->hasException))
686 return Encode::undefined();
688 return result;
690 return v4->throwTypeError();
691 else if (Value::fromReturnedValue(thisObject).isEmpty()) {
692 Scope scope(v4);
694 return v4->throwReferenceError(s);
695 }
696
697 return thisObject;
698}
699
701{
702 return f->engine()->throwTypeError(QStringLiteral("Cannot call a class constructor without |new|"));
703}
704
706
708
709void Heap::BoundFunction::init(QV4::ExecutionContext *scope, QV4::FunctionObject *target,
710 const Value &boundThis, QV4::MemberData *boundArgs)
711{
712 Scope s(scope);
713 Heap::FunctionObject::init(scope, QStringLiteral("__bound function__"));
714 this->target.set(s.engine, target->d());
715 this->boundArgs.set(s.engine, boundArgs ? boundArgs->d() : nullptr);
716 this->boundThis.set(scope->engine(), boundThis);
717
718 if (!target->isConstructor())
719 jsConstruct = nullptr;
720
721 ScopedObject f(s, this);
722
723 ScopedValue l(s, target->get(s.engine->id_length()));
724 int len = l->toUInt32();
725 if (boundArgs)
726 len -= boundArgs->size();
727 if (len < 0)
728 len = 0;
729 f->defineReadonlyConfigurableProperty(s.engine->id_length(), Value::fromInt32(len));
730
731 ScopedProperty pd(s);
732 pd->value = s.engine->thrower();
733 pd->set = s.engine->thrower();
734 f->insertMember(s.engine->id_arguments(), pd, Attr_Accessor|Attr_NotConfigurable|Attr_NotEnumerable);
735 f->insertMember(s.engine->id_caller(), pd, Attr_Accessor|Attr_NotConfigurable|Attr_NotEnumerable);
736}
737
738ReturnedValue BoundFunction::virtualCall(const FunctionObject *fo, const Value *, const Value *argv, int argc)
739{
740 QV4::ExecutionEngine *v4 = fo->engine();
741 if (v4->hasException)
742 return Encode::undefined();
743
744 const BoundFunction *f = static_cast<const BoundFunction *>(fo);
745 Scope scope(v4);
746 Scoped<MemberData> boundArgs(scope, f->boundArgs());
747 ScopedFunctionObject target(scope, f->target());
748 JSCallArguments jsCallData(scope, (boundArgs ? boundArgs->size() : 0) + argc);
749 *jsCallData.thisObject = f->boundThis();
750 Value *argp = jsCallData.args;
751 if (boundArgs) {
752 memcpy(argp, boundArgs->data(), boundArgs->size()*sizeof(Value));
753 argp += boundArgs->size();
754 }
755 memcpy(argp, argv, argc*sizeof(Value));
756 return checkedResult(v4, target->call(jsCallData));
757}
758
760{
761 const BoundFunction *f = static_cast<const BoundFunction *>(fo);
762 Scope scope(f->engine());
763
764 if (scope.hasException())
765 return Encode::undefined();
766
767 Scoped<MemberData> boundArgs(scope, f->boundArgs());
768 ScopedFunctionObject target(scope, f->target());
769 JSCallArguments jsCallData(scope, (boundArgs ? boundArgs->size() : 0) + argc);
770 Value *argp = jsCallData.args;
771 if (boundArgs) {
772 memcpy(argp, boundArgs->data(), boundArgs->size()*sizeof(Value));
773 argp += boundArgs->size();
774 }
775 memcpy(argp, argv, argc*sizeof(Value));
776 return target->callAsConstructor(jsCallData);
777}
static constexpr QChar fromLatin1(char c) noexcept
Converts the Latin-1 character c to its equivalent QChar.
Definition qchar.h:461
pointer data()
Definition qlist.h:414
\inmodule QtCore
Definition qmetatype.h:320
\inmodule QtCore
Definition qobject.h:90
void setCode(const QString &code, int lineno, bool qmlMode=true, CodeContinuation codeContinuation=CodeContinuation::Reset)
\inmodule QtCore
Definition qstringview.h:76
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
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
QV4::CompiledData::CompilationUnit generateCompilationUnit(bool generateUnitData=true)
static QQmlRefPointer< ExecutableCompilationUnit > create()
ObjectType::Data * allocate(Args &&... args)
Definition qv4mm_p.h:199
ObjectType::Data * allocObject(Heap::InternalClass *ic, Args &&... args)
Definition qv4mm_p.h:183
static void exec(MetaTypesStackFrame *frame, ExecutionEngine *engine)
void generateFromFunctionExpression(const QString &fileName, const QString &sourceCode, QQmlJS::AST::FunctionExpression *ast, Compiler::Module *module)
EGLContext ctx
object setProperty("down", true)
type name READ getFunction WRITE setFunction
[0]
double e
QList< QVariant > arguments
\qmltype Particle \inqmlmodule QtQuick.Particles
ReturnedValue convertAndCall(ExecutionEngine *engine, const QQmlPrivate::AOTCompiledFunction *aotFunction, const Value *thisObject, const Value *argv, int argc, Callable call)
quint64 ReturnedValue
ReturnedValue coerceAndCall(ExecutionEngine *engine, const Function::JSTypedFunction *typedFunction, const CompiledData::Function *compiledFunction, const Value *thisObject, const Value *argv, int argc, Callable call)
ReturnedValue checkedResult(QV4::ExecutionEngine *v4, ReturnedValue result)
@ Attr_NotConfigurable
@ Attr_NotEnumerable
@ Attr_ReadOnly
@ Attr_Accessor
static void * context
#define Q_UNLIKELY(x)
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction function
constexpr const T & qMin(const T &a, const T &b)
Definition qminmax.h:40
GLboolean GLboolean GLboolean b
const GLfloat * m
GLboolean GLboolean GLboolean GLboolean a
[7]
GLsizei GLenum GLenum * types
GLfloat GLfloat f
GLenum target
GLuint name
GLfloat n
GLhandleARB obj
[2]
const GLubyte * c
GLenum GLsizei len
GLdouble GLdouble t
Definition qopenglext.h:243
GLuint64EXT * result
[6]
GLdouble s
[6]
Definition qopenglext.h:235
GLfloat GLfloat p
[1]
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
QLatin1StringView QLatin1String
Definition qstringfwd.h:31
#define QStringLiteral(str)
static QT_BEGIN_NAMESPACE void init(QTextBoundaryFinder::BoundaryType type, QStringView str, QCharAttributes *attributes)
unsigned int uint
Definition qtypes.h:29
static ReturnedValue qfoDoCall(const QV4::FunctionObject *fo, const QV4::Value *thisObject, const QV4::Value *argv, int argc)
#define CHECK_EXCEPTION()
#define DEFINE_OBJECT_VTABLE(classname)
QObject::connect nullptr
QFrame frame
[0]
QJSValue fun
[0]
QJSValue global
QJSEngine engine
[0]
\inmodule QtCore \reentrant
Definition qchar.h:17
static bool isNonStrictArgumentsObject(Managed *m)
Heap::FunctionObject * target() const
static Heap::BoundFunction * create(ExecutionContext *scope, FunctionObject *target, const Value &boundThis, QV4::MemberData *boundArgs)
Heap::MemberData * boundArgs() const
static constexpr ReturnedValue undefined()
Heap::InternalClass * internalClasses(InternalClassType icType)
MemoryManager * memoryManager
ExecutionContext * rootContext() const
Heap::String * newString(const QString &s=QString())
QV4::Debugging::Debugger * debugger() const
String * id_length() const
ReturnedValue throwReferenceError(const Value &value)
String * id_toString() const
String * id_prototype() const
String * id_name() const
int safeForAllocLength(qint64 len64)
ExecutionContext * scriptContext() const
String * id_empty() const
Symbol * symbol_hasInstance() const
ReturnedValue throwSyntaxError(const QString &message)
ReturnedValue throwTypeError()
static QQmlRefPointer< ExecutableCompilationUnit > parse(ExecutionEngine *engine, const Value *argv, int argc, Type t=Type_Function)
static Heap::FunctionObject * createMemberFunction(ExecutionContext *scope, Function *function, Object *homeObject, String *name)
static Heap::FunctionObject * createScriptFunction(ExecutionContext *scope, Function *function)
ReturnedValue getHomeObject() const
static Heap::FunctionObject * createBuiltinFunction(ExecutionEngine *engine, StringOrSymbol *nameOrSymbol, VTable::Call code, int argumentCount)
ReturnedValue protoProperty() const
ReturnedValue name() const
static Heap::FunctionObject * createConstructorFunction(ExecutionContext *scope, Function *function, Object *homeObject, bool isDerivedConstructor)
QQmlSourceLocation sourceLocation() const
void createDefaultPrototypeProperty(uint protoConstructorSlot)
ReturnedValue call(const JSCallData &data) const
Function * function() const
Heap::ExecutionContext * scope() const
static ReturnedValue method_bind(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_call(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_hasInstance(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_apply(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_toString(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
const JSTypedFunction * jsTypedFunction
bool isArrowFunction() const
const CompiledData::Function * compiledFunction
const QQmlPrivate::AOTCompiledFunction * aotCompiledFunction
void init(QV4::ExecutionContext *scope, Function *function, QV4::String *name=nullptr)
void init(QV4::ExecutionContext *scope)
Heap::InternalClass * internalClass() const
ExecutionEngine * engine() const
static Heap::MemberData * allocate(QV4::ExecutionEngine *e, uint n, Heap::MemberData *old=nullptr)
void set(EngineBase *e, uint index, Value v)
uint size() const
void defineDefaultProperty(StringOrSymbol *name, const Value &value, PropertyAttributes attributes=Attr_Data|Attr_NotEnumerable)
bool protoHasArray()
qint64 getLength() const
Heap::ArrayData * arrayData() const
ArrayData::Type arrayType() const
bool set(StringOrSymbol *name, const Value &v, ThrowOnFailure shouldThrow)
void defineReadonlyConfigurableProperty(const QString &name, const Value &value)
void defineReadonlyProperty(const QString &name, const Value &value)
ReturnedValue get(StringOrSymbol *name, bool *hasProperty=nullptr, const Value *receiver=nullptr) const
bool hasException() const
ExecutionEngine * engine
Heap::InternalClass * classForConstructor() const
constexpr ReturnedValue asReturnedValue() const
bool isNullOrUndefined() const
bool isUndefined() const
QString toQString() const
static constexpr VTable::CallAsConstructor virtualCallAsConstructor
static constexpr VTable::Call virtualCall
static constexpr VTable::CallWithMetaTypes virtualCallWithMetaTypes
static constexpr VTable::InstanceOf virtualInstanceOf
ReturnedValue(* Call)(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
Definition qv4vtable_p.h:52
void(* CallWithMetaTypes)(const FunctionObject *, QObject *, void **, const QMetaType *, int)
Definition qv4vtable_p.h:53
static constexpr Value fromInt32(int i)
Definition qv4value_p.h:187
bool isFunctionObject() const
Definition qv4value_p.h:309
static constexpr Value undefinedValue()
Definition qv4value_p.h:191
QML_NEARLY_ALWAYS_INLINE Object * objectValue() const
Definition qv4value_p.h:70
static constexpr Value fromReturnedValue(ReturnedValue val)
Definition qv4value_p.h:165
const T * as() const
Definition qv4value_p.h:132
QString toQString() const
Definition qv4value.cpp:158
static constexpr Value emptyValue()
Definition qv4value_p.h:179
bool isObject() const
Definition qv4value_p.h:302
Definition moc.h:24