diff options
author | Lars Knoll <lars.knoll@qt.io> | 2017-10-30 10:38:55 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2017-11-13 08:56:14 +0000 |
commit | 3daf05ec2d7dbc408e2c302cdade667ec719d847 (patch) | |
tree | a5efab7b4a0bf381da6aa9ae0e44ea50cce9ea59 /src/qml/jsruntime/qv4object.cpp | |
parent | 831ddc54932d2681712ca9fa3e94484ae11d59f7 (diff) |
Introduce new calling convention for builtin functions
And implement Function.apply()/call() with it.
Change-Id: I028c82d5f9adfd23328d669db1adccec9de5824c
Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4object.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4object.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/qml/jsruntime/qv4object.cpp b/src/qml/jsruntime/qv4object.cpp index 1859466348..bfc4eb9ce1 100644 --- a/src/qml/jsruntime/qv4object.cpp +++ b/src/qml/jsruntime/qv4object.cpp @@ -170,6 +170,27 @@ void Object::defineDefaultProperty(String *name, ReturnedValue (*code)(const Bui defineDefaultProperty(name, function); } +void Object::defineDefaultProperty(const QString &name, ReturnedValue (*code)(const FunctionObject *, const Value *thisObject, const Value *argv, int argc), int argumentCount) +{ + ExecutionEngine *e = engine(); + Scope scope(e); + ScopedString s(scope, e->newIdentifier(name)); + ExecutionContext *global = e->rootContext(); + ScopedFunctionObject function(scope, BuiltinFunction::create(global, s, code)); + function->defineReadonlyConfigurableProperty(e->id_length(), Primitive::fromInt32(argumentCount)); + defineDefaultProperty(s, function); +} + +void Object::defineDefaultProperty(String *name, ReturnedValue (*code)(const FunctionObject *, const Value *thisObject, const Value *argv, int argc), int argumentCount) +{ + ExecutionEngine *e = engine(); + Scope scope(e); + ExecutionContext *global = e->rootContext(); + ScopedFunctionObject function(scope, BuiltinFunction::create(global, name, code)); + function->defineReadonlyConfigurableProperty(e->id_length(), Primitive::fromInt32(argumentCount)); + defineDefaultProperty(name, function); +} + void Object::defineAccessorProperty(const QString &name, ReturnedValue (*getter)(const BuiltinFunction *, CallData *), ReturnedValue (*setter)(const BuiltinFunction *, CallData *)) { |