diff options
-rw-r--r-- | src/qml/jsruntime/qv4dateobject.cpp | 4 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4engine.cpp | 12 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4functionobject.cpp | 12 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4functionobject_p.h | 9 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4object.cpp | 26 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4object_p.h | 13 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4objectproto.cpp | 6 | ||||
-rw-r--r-- | src/qml/types/qquickworkerscript.cpp | 3 | ||||
-rw-r--r-- | tests/auto/qml/debugger/qv4debugger/tst_qv4debugger.cpp | 3 | ||||
-rw-r--r-- | tests/auto/qml/ecmascripttests/TestExpectations | 4 |
10 files changed, 36 insertions, 56 deletions
diff --git a/src/qml/jsruntime/qv4dateobject.cpp b/src/qml/jsruntime/qv4dateobject.cpp index 394a7f3de3..8ad4ee8116 100644 --- a/src/qml/jsruntime/qv4dateobject.cpp +++ b/src/qml/jsruntime/qv4dateobject.cpp @@ -852,9 +852,7 @@ void DatePrototype::init(ExecutionEngine *engine, Object *ctor) QString toGmtString(QStringLiteral("toGMTString")); ScopedString us(scope, engine->newIdentifier(toUtcString)); ScopedString gs(scope, engine->newIdentifier(toGmtString)); - ExecutionContext *global = engine->rootContext(); - ScopedFunctionObject toUtcGmtStringFn(scope, FunctionObject::createBuiltinFunction(global, us, method_toUTCString)); - toUtcGmtStringFn->defineReadonlyConfigurableProperty(engine->id_length(), Primitive::fromInt32(0)); + ScopedFunctionObject toUtcGmtStringFn(scope, FunctionObject::createBuiltinFunction(engine, us, method_toUTCString, 0)); defineDefaultProperty(us, toUtcGmtStringFn); defineDefaultProperty(gs, toUtcGmtStringFn); } diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp index 0bd2894fe3..70072dabca 100644 --- a/src/qml/jsruntime/qv4engine.cpp +++ b/src/qml/jsruntime/qv4engine.cpp @@ -366,8 +366,7 @@ ExecutionEngine::ExecutionEngine(QJSEngine *jsEngine) classes[Class_ErrorProto] = ic->addMember(id_name()->identifier(), Attr_Data|Attr_NotEnumerable, &index); Q_ASSERT(index == ErrorPrototype::Index_Name); - jsObjects[GetStack_Function] = FunctionObject::createBuiltinFunction(rootContext(), str = newIdentifier(QStringLiteral("stack")), ErrorObject::method_get_stack); - getStackFunction()->defineReadonlyProperty(id_length(), Primitive::fromInt32(0)); + jsObjects[GetStack_Function] = FunctionObject::createBuiltinFunction(this, str = newIdentifier(QStringLiteral("stack")), ErrorObject::method_get_stack, 0); jsObjects[ErrorProto] = memoryManager->allocObject<ErrorPrototype>(classes[Class_ErrorProto]); ic = classes[Class_ErrorProto]->changePrototype(errorPrototype()->d()); @@ -500,11 +499,8 @@ ExecutionEngine::ExecutionEngine(QJSEngine *jsEngine) Scope scope(this); ScopedString pi(scope, newIdentifier(piString)); ScopedString pf(scope, newIdentifier(pfString)); - ExecutionContext *global = rootContext(); - ScopedFunctionObject parseIntFn(scope, FunctionObject::createBuiltinFunction(global, pi, GlobalFunctions::method_parseInt)); - ScopedFunctionObject parseFloatFn(scope, FunctionObject::createBuiltinFunction(global, pf, GlobalFunctions::method_parseFloat)); - parseIntFn->defineReadonlyConfigurableProperty(id_length(), Primitive::fromInt32(2)); - parseFloatFn->defineReadonlyConfigurableProperty(id_length(), Primitive::fromInt32(1)); + ScopedFunctionObject parseIntFn(scope, FunctionObject::createBuiltinFunction(this, pi, GlobalFunctions::method_parseInt, 2)); + ScopedFunctionObject parseFloatFn(scope, FunctionObject::createBuiltinFunction(this, pf, GlobalFunctions::method_parseFloat, 1)); globalObject->defineDefaultProperty(piString, parseIntFn); globalObject->defineDefaultProperty(pfString, parseFloatFn); numberObject->defineDefaultProperty(piString, parseIntFn); @@ -521,7 +517,7 @@ ExecutionEngine::ExecutionEngine(QJSEngine *jsEngine) globalObject->defineDefaultProperty(QStringLiteral("unescape"), GlobalFunctions::method_unescape, 1); ScopedString name(scope, newString(QStringLiteral("thrower"))); - jsObjects[ThrowerObject] = FunctionObject::createBuiltinFunction(global, name, ::throwTypeError); + jsObjects[ThrowerObject] = FunctionObject::createBuiltinFunction(this, name, ::throwTypeError, 0); ScopedProperty pd(scope); pd->value = thrower(); diff --git a/src/qml/jsruntime/qv4functionobject.cpp b/src/qml/jsruntime/qv4functionobject.cpp index 98db060a00..a684e1c5d3 100644 --- a/src/qml/jsruntime/qv4functionobject.cpp +++ b/src/qml/jsruntime/qv4functionobject.cpp @@ -179,6 +179,18 @@ Heap::FunctionObject *FunctionObject::createScriptFunction(ExecutionContext *sco return scope->engine()->memoryManager->allocate<ScriptFunction>(scope, function); } +Heap::FunctionObject *FunctionObject::createBuiltinFunction(ExecutionEngine *engine, StringOrSymbol *nameOrSymbol, jsCallFunction code, int argumentCount) +{ + Scope scope(engine); + ScopedString name(scope, nameOrSymbol); + if (!name) + name = engine->newString(QChar::fromLatin1('[') + nameOrSymbol->toQString().midRef(1) + QChar::fromLatin1(']')); + + ScopedFunctionObject function(scope, engine->memoryManager->allocate<FunctionObject>(engine->rootContext(), name, code)); + function->defineReadonlyConfigurableProperty(engine->id_length(), Primitive::fromInt32(argumentCount)); + return function->d(); +} + bool FunctionObject::isBinding() const { return d()->vtable() == QQmlBindingFunction::staticVTable(); diff --git a/src/qml/jsruntime/qv4functionobject_p.h b/src/qml/jsruntime/qv4functionobject_p.h index 64cd0b96d3..c9efee1a46 100644 --- a/src/qml/jsruntime/qv4functionobject_p.h +++ b/src/qml/jsruntime/qv4functionobject_p.h @@ -64,9 +64,6 @@ namespace QV4 { struct IndexedBuiltinFunction; struct JSCallData; -typedef ReturnedValue (*jsCallFunction)(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); -typedef ReturnedValue (*jsConstructFunction)(const FunctionObject *, const Value *argv, int argc); - namespace Heap { @@ -168,11 +165,7 @@ struct Q_QML_EXPORT FunctionObject: Object { static ReturnedValue call(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc); static Heap::FunctionObject *createScriptFunction(ExecutionContext *scope, Function *function); - static Heap::FunctionObject *createBuiltinFunction(ExecutionContext *scope, String *name, - ReturnedValue (*code)(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)) - { - return scope->engine()->memoryManager->allocate<FunctionObject>(scope, name, code); - } + static Heap::FunctionObject *createBuiltinFunction(ExecutionEngine *engine, StringOrSymbol *nameOrSymbol, jsCallFunction code, int argumentCount); bool strictMode() const { return d()->function ? d()->function->isStrict() : false; } bool isBinding() const; diff --git a/src/qml/jsruntime/qv4object.cpp b/src/qml/jsruntime/qv4object.cpp index 7bb339bf0d..a1a126a0e0 100644 --- a/src/qml/jsruntime/qv4object.cpp +++ b/src/qml/jsruntime/qv4object.cpp @@ -156,34 +156,26 @@ void Object::defineDefaultProperty(const QString &name, const Value &value) defineDefaultProperty(s, value); } -void Object::defineDefaultProperty(const QString &name, ReturnedValue (*code)(const FunctionObject *, const Value *thisObject, const Value *argv, int argc), +void Object::defineDefaultProperty(const QString &name, jsCallFunction code, int argumentCount, PropertyAttributes attributes) { ExecutionEngine *e = engine(); Scope scope(e); ScopedString s(scope, e->newIdentifier(name)); - ExecutionContext *global = e->rootContext(); - ScopedFunctionObject function(scope, FunctionObject::createBuiltinFunction(global, s, code)); - function->defineReadonlyConfigurableProperty(e->id_length(), Primitive::fromInt32(argumentCount)); + ScopedFunctionObject function(scope, FunctionObject::createBuiltinFunction(e, s, code, argumentCount)); defineDefaultProperty(s, function, attributes); } -void Object::defineDefaultProperty(StringOrSymbol *nameOrSymbol, ReturnedValue (*code)(const FunctionObject *, const Value *thisObject, const Value *argv, int argc), +void Object::defineDefaultProperty(StringOrSymbol *nameOrSymbol, jsCallFunction code, int argumentCount, PropertyAttributes attributes) { ExecutionEngine *e = engine(); Scope scope(e); - ExecutionContext *global = e->rootContext(); - ScopedString name(scope, nameOrSymbol); - if (!name) - name = e->newString(QChar::fromLatin1('[') + nameOrSymbol->toQString().midRef(1) + QChar::fromLatin1(']')); - ScopedFunctionObject function(scope, FunctionObject::createBuiltinFunction(global, name, code)); - function->defineReadonlyConfigurableProperty(e->id_length(), Primitive::fromInt32(argumentCount)); + ScopedFunctionObject function(scope, FunctionObject::createBuiltinFunction(e, nameOrSymbol, code, argumentCount)); defineDefaultProperty(nameOrSymbol, function, attributes); } -void Object::defineAccessorProperty(const QString &name, ReturnedValue (*getter)(const FunctionObject *, const Value *, const Value *, int), - ReturnedValue (*setter)(const FunctionObject *, const Value *, const Value *, int)) +void Object::defineAccessorProperty(const QString &name, jsCallFunction getter, jsCallFunction setter) { ExecutionEngine *e = engine(); Scope scope(e); @@ -191,15 +183,13 @@ void Object::defineAccessorProperty(const QString &name, ReturnedValue (*getter) defineAccessorProperty(s, getter, setter); } -void Object::defineAccessorProperty(String *name, ReturnedValue (*getter)(const FunctionObject *, const Value *, const Value *, int), - ReturnedValue (*setter)(const FunctionObject *, const Value *, const Value *, int)) +void Object::defineAccessorProperty(StringOrSymbol *name, jsCallFunction getter, jsCallFunction setter) { ExecutionEngine *v4 = engine(); QV4::Scope scope(v4); ScopedProperty p(scope); - ExecutionContext *global = v4->rootContext(); - p->setGetter(ScopedFunctionObject(scope, (getter ? FunctionObject::createBuiltinFunction(global, name, getter) : nullptr))); - p->setSetter(ScopedFunctionObject(scope, (setter ? FunctionObject::createBuiltinFunction(global, name, setter) : nullptr))); + p->setGetter(ScopedFunctionObject(scope, (getter ? FunctionObject::createBuiltinFunction(v4, name, getter, 0) : nullptr))); + p->setSetter(ScopedFunctionObject(scope, (setter ? FunctionObject::createBuiltinFunction(v4, name, setter, 1) : nullptr))); insertMember(name, p, QV4::Attr_Accessor|QV4::Attr_NotConfigurable|QV4::Attr_NotEnumerable); } diff --git a/src/qml/jsruntime/qv4object_p.h b/src/qml/jsruntime/qv4object_p.h index 15d42e8098..44ad35b44b 100644 --- a/src/qml/jsruntime/qv4object_p.h +++ b/src/qml/jsruntime/qv4object_p.h @@ -64,6 +64,9 @@ QT_BEGIN_NAMESPACE namespace QV4 { +typedef ReturnedValue (*jsCallFunction)(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); +typedef ReturnedValue (*jsConstructFunction)(const FunctionObject *, const Value *argv, int argc); + namespace Heap { #define ObjectMembers(class, Member) \ @@ -275,14 +278,12 @@ struct Q_QML_EXPORT Object: Managed { insertMember(name, value, attributes); } void defineDefaultProperty(const QString &name, const Value &value); - void defineDefaultProperty(const QString &name, ReturnedValue (*code)(const FunctionObject *, const Value *thisObject, const Value *argv, int argc), + void defineDefaultProperty(const QString &name, jsCallFunction code, int argumentCount = 0, PropertyAttributes attributes = Attr_Data|Attr_NotEnumerable); - void defineDefaultProperty(StringOrSymbol *name, ReturnedValue (*code)(const FunctionObject *, const Value *thisObject, const Value *argv, int argc), + void defineDefaultProperty(StringOrSymbol *name, jsCallFunction code, int argumentCount = 0, PropertyAttributes attributes = Attr_Data|Attr_NotEnumerable); - void defineAccessorProperty(const QString &name, ReturnedValue (*getter)(const FunctionObject *, const Value *, const Value *, int), - ReturnedValue (*setter)(const FunctionObject *, const Value *, const Value *, int)); - void defineAccessorProperty(String *name, ReturnedValue (*getter)(const FunctionObject *, const Value *, const Value *, int), - ReturnedValue (*setter)(const FunctionObject *, const Value *, const Value *, int)); + void defineAccessorProperty(const QString &name, jsCallFunction getter, jsCallFunction setter); + void defineAccessorProperty(StringOrSymbol *name, jsCallFunction getter, jsCallFunction setter); /* Fixed: Writable: false, Enumerable: false, Configurable: false */ void defineReadonlyProperty(const QString &name, const Value &value); void defineReadonlyProperty(String *name, const Value &value); diff --git a/src/qml/jsruntime/qv4objectproto.cpp b/src/qml/jsruntime/qv4objectproto.cpp index 1cf6ff4ed8..363b53a336 100644 --- a/src/qml/jsruntime/qv4objectproto.cpp +++ b/src/qml/jsruntime/qv4objectproto.cpp @@ -119,11 +119,7 @@ void ObjectPrototype::init(ExecutionEngine *v4, Object *ctor) defineDefaultProperty(QStringLiteral("__defineGetter__"), method_defineGetter, 2); defineDefaultProperty(QStringLiteral("__defineSetter__"), method_defineSetter, 2); - ExecutionContext *global = v4->rootContext(); - ScopedProperty p(scope); - p->value = FunctionObject::createBuiltinFunction(global, v4->id___proto__(), method_get_proto); - p->set = FunctionObject::createBuiltinFunction(global, v4->id___proto__(), method_set_proto); - insertMember(v4->id___proto__(), p, Attr_Accessor|Attr_NotEnumerable); + defineAccessorProperty(v4->id___proto__(), method_get_proto, method_set_proto); } ReturnedValue ObjectPrototype::method_getPrototypeOf(const FunctionObject *b, const Value *, const Value *argv, int argc) diff --git a/src/qml/types/qquickworkerscript.cpp b/src/qml/types/qquickworkerscript.cpp index 859f647ce4..501de392e3 100644 --- a/src/qml/types/qquickworkerscript.cpp +++ b/src/qml/types/qquickworkerscript.cpp @@ -250,8 +250,7 @@ void QQuickWorkerScriptEnginePrivate::WorkerEngine::init() QV4::ScopedFunctionObject createsendconstructor(scope, createsendscript.run()); Q_ASSERT(!scope.engine->hasException); QV4::ScopedString name(scope, m_v4Engine->newString(QStringLiteral("sendMessage"))); - QV4::ScopedValue function(scope, QV4::FunctionObject::createBuiltinFunction(globalContext, name, - QQuickWorkerScriptEnginePrivate::method_sendMessage)); + QV4::ScopedValue function(scope, QV4::FunctionObject::createBuiltinFunction(m_v4Engine, name, method_sendMessage, 1)); QV4::JSCallData jsCallData(scope, 1); jsCallData->args[0] = function; *jsCallData->thisObject = m_v4Engine->global(); diff --git a/tests/auto/qml/debugger/qv4debugger/tst_qv4debugger.cpp b/tests/auto/qml/debugger/qv4debugger/tst_qv4debugger.cpp index ccb3a2dcdc..7d99ab0a90 100644 --- a/tests/auto/qml/debugger/qv4debugger/tst_qv4debugger.cpp +++ b/tests/auto/qml/debugger/qv4debugger/tst_qv4debugger.cpp @@ -86,8 +86,7 @@ public: QV4::Scope scope(v4); QV4::ScopedString name(scope, v4->newString(functionName)); - QV4::ScopedContext ctx(scope, v4->rootContext()); - QV4::ScopedValue function(scope, FunctionObject::createBuiltinFunction(ctx, name, injectedFunction)); + QV4::ScopedValue function(scope, FunctionObject::createBuiltinFunction(v4, name, injectedFunction, 0)); v4->globalObject->put(name, function); } diff --git a/tests/auto/qml/ecmascripttests/TestExpectations b/tests/auto/qml/ecmascripttests/TestExpectations index bca6b9892d..517d7fe3b4 100644 --- a/tests/auto/qml/ecmascripttests/TestExpectations +++ b/tests/auto/qml/ecmascripttests/TestExpectations @@ -243,7 +243,6 @@ built-ins/ArrayBuffer/proto-from-ctor-realm.js fails built-ins/ArrayBuffer/prototype-from-newtarget.js fails built-ins/ArrayBuffer/prototype/Symbol.toStringTag.js fails built-ins/ArrayBuffer/prototype/byteLength/detached-buffer.js fails -built-ins/ArrayBuffer/prototype/byteLength/length.js fails built-ins/ArrayBuffer/prototype/byteLength/name.js fails built-ins/ArrayBuffer/prototype/byteLength/prop-desc.js fails built-ins/ArrayBuffer/prototype/slice/end-default-if-absent.js fails @@ -378,15 +377,12 @@ built-ins/DataView/newtarget-undefined-throws.js fails built-ins/DataView/proto-from-ctor-realm.js fails built-ins/DataView/prototype/Symbol.toStringTag.js fails built-ins/DataView/prototype/buffer/detached-buffer.js fails -built-ins/DataView/prototype/buffer/length.js fails built-ins/DataView/prototype/buffer/name.js fails built-ins/DataView/prototype/buffer/prop-desc.js fails built-ins/DataView/prototype/byteLength/detached-buffer.js fails -built-ins/DataView/prototype/byteLength/length.js fails built-ins/DataView/prototype/byteLength/name.js fails built-ins/DataView/prototype/byteLength/prop-desc.js fails built-ins/DataView/prototype/byteOffset/detached-buffer.js fails -built-ins/DataView/prototype/byteOffset/length.js fails built-ins/DataView/prototype/byteOffset/name.js fails built-ins/DataView/prototype/byteOffset/prop-desc.js fails built-ins/DataView/prototype/getFloat32/detached-buffer-after-toindex-byteoffset.js fails |