diff options
-rw-r--r-- | src/qml/jsruntime/qv4arraybuffer.cpp | 3 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4dataview.cpp | 4 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4mathobject.cpp | 4 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4objectproto.cpp | 34 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4typedarray.cpp | 10 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4typedarray_p.h | 3 | ||||
-rw-r--r-- | tests/auto/qml/ecmascripttests/TestExpectations | 11 |
7 files changed, 48 insertions, 21 deletions
diff --git a/src/qml/jsruntime/qv4arraybuffer.cpp b/src/qml/jsruntime/qv4arraybuffer.cpp index dd28a90cb7..b0c2ba597a 100644 --- a/src/qml/jsruntime/qv4arraybuffer.cpp +++ b/src/qml/jsruntime/qv4arraybuffer.cpp @@ -41,6 +41,7 @@ #include "qv4dataview_p.h" #include "qv4string_p.h" #include "qv4jscall_p.h" +#include "qv4symbol_p.h" using namespace QV4; @@ -157,6 +158,8 @@ void ArrayBufferPrototype::init(ExecutionEngine *engine, Object *ctor) defineAccessorProperty(QStringLiteral("byteLength"), method_get_byteLength, nullptr); defineDefaultProperty(QStringLiteral("slice"), method_slice, 2); defineDefaultProperty(QStringLiteral("toString"), method_toString, 0); + ScopedString name(scope, engine->newString(QStringLiteral("ArrayBuffer"))); + defineReadonlyConfigurableProperty(scope.engine->symbol_toStringTag(), name); } ReturnedValue ArrayBufferPrototype::method_get_byteLength(const FunctionObject *b, const Value *thisObject, const Value *, int) diff --git a/src/qml/jsruntime/qv4dataview.cpp b/src/qml/jsruntime/qv4dataview.cpp index 5a6599aca0..354eaad7dc 100644 --- a/src/qml/jsruntime/qv4dataview.cpp +++ b/src/qml/jsruntime/qv4dataview.cpp @@ -40,6 +40,7 @@ #include "qv4dataview_p.h" #include "qv4arraybuffer_p.h" #include "qv4string_p.h" +#include "qv4symbol_p.h" #include <QtCore/private/qnumeric_p.h> #include "qendian.h" @@ -110,6 +111,9 @@ void DataViewPrototype::init(ExecutionEngine *engine, Object *ctor) defineDefaultProperty(QStringLiteral("setFloat32"), method_setFloat<float>, 2); defineDefaultProperty(QStringLiteral("setFloat64"), method_setFloat<double>, 2); + ScopedString name(scope, engine->newString(QStringLiteral("DataView"))); + defineReadonlyConfigurableProperty(scope.engine->symbol_toStringTag(), name); + // For backword compatibility defineDefaultProperty(QStringLiteral("getUInt8"), method_getChar<unsigned char>, 1); defineDefaultProperty(QStringLiteral("getUInt16"), method_get<unsigned short>, 1); diff --git a/src/qml/jsruntime/qv4mathobject.cpp b/src/qml/jsruntime/qv4mathobject.cpp index 43459211f6..0e91a30ba3 100644 --- a/src/qml/jsruntime/qv4mathobject.cpp +++ b/src/qml/jsruntime/qv4mathobject.cpp @@ -39,6 +39,7 @@ #include "qv4mathobject_p.h" #include "qv4objectproto_p.h" +#include "qv4symbol_p.h" #include <QtCore/qdatetime.h> #include <QtCore/qmath.h> @@ -90,6 +91,9 @@ void Heap::MathObject::init() m->defineDefaultProperty(QStringLiteral("sin"), QV4::MathObject::method_sin, 1); m->defineDefaultProperty(QStringLiteral("sqrt"), QV4::MathObject::method_sqrt, 1); m->defineDefaultProperty(QStringLiteral("tan"), QV4::MathObject::method_tan, 1); + + ScopedString name(scope, scope.engine->newString(QStringLiteral("Math"))); + m->defineReadonlyConfigurableProperty(scope.engine->symbol_toStringTag(), name); } static Q_ALWAYS_INLINE double copySign(double x, double y) diff --git a/src/qml/jsruntime/qv4objectproto.cpp b/src/qml/jsruntime/qv4objectproto.cpp index ebf1c713fb..478e2e5915 100644 --- a/src/qml/jsruntime/qv4objectproto.cpp +++ b/src/qml/jsruntime/qv4objectproto.cpp @@ -47,6 +47,7 @@ #include "qv4objectiterator_p.h" #include "qv4string_p.h" #include "qv4jscall_p.h" +#include "qv4symbol_p.h" #include <QtCore/QDateTime> #include <QtCore/QStringList> @@ -532,20 +533,33 @@ ReturnedValue ObjectPrototype::method_setPrototypeOf(const FunctionObject *f, co ReturnedValue ObjectPrototype::method_toString(const FunctionObject *b, const Value *thisObject, const Value *, int) { ExecutionEngine *v4 = b->engine(); + QString string; if (thisObject->isUndefined()) { - return Encode(v4->newString(QStringLiteral("[object Undefined]"))); + string = QStringLiteral("[object Undefined]"); } else if (thisObject->isNull()) { - return Encode(v4->newString(QStringLiteral("[object Null]"))); - } else if (thisObject->isBoolean()) { - return Encode(v4->newString(QStringLiteral("[object Boolean]"))); - } else if (thisObject->isNumber()) { - return Encode(v4->newString(QStringLiteral("[object Number]"))); + string = QStringLiteral("[object Null]"); } else { - Q_ASSERT(thisObject->isManaged()); - const Managed *m = static_cast<const Managed *>(thisObject); - QString className = m->className(); - return Encode(v4->newString(QStringLiteral("[object %1]").arg(className))); + const Object *o = thisObject->as<Object>(); + if (!o) { + // primitive, get the proper prototype + if (thisObject->isBoolean()) + o = v4->booleanPrototype(); + else if (thisObject->isNumber()) + o = v4->numberPrototype(); + else if (thisObject->isString()) + o = v4->stringPrototype(); + else if (thisObject->isSymbol()) + o = v4->symbolPrototype(); + Q_ASSERT(o); + } + QString name = o->className(); + Scope scope(v4); + ScopedString toStringTag(scope, o->get(v4->symbol_toStringTag())); + if (toStringTag) + name = toStringTag->toQString(); + string = QStringLiteral("[object %1]").arg(name); } + return Encode(v4->newString(string)); } ReturnedValue ObjectPrototype::method_toLocaleString(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) diff --git a/src/qml/jsruntime/qv4typedarray.cpp b/src/qml/jsruntime/qv4typedarray.cpp index b3c6f0e094..2fa4a9ecaf 100644 --- a/src/qml/jsruntime/qv4typedarray.cpp +++ b/src/qml/jsruntime/qv4typedarray.cpp @@ -623,6 +623,15 @@ ReturnedValue IntrinsicTypedArrayPrototype::method_subarray(const FunctionObject return constructor->callAsConstructor(arguments, 3); } +ReturnedValue IntrinsicTypedArrayPrototype::method_get_toStringTag(const FunctionObject *, const Value *thisObject, const Value *, int) +{ + const TypedArray *a = thisObject->as<TypedArray>(); + if (!a) + return Encode::undefined(); + + return a->engine()->newString(QString::fromLatin1(a->d()->type->name))->asReturnedValue(); +} + ReturnedValue IntrinsicTypedArrayCtor::callAsConstructor(const FunctionObject *f, const Value *, int) { return f->engine()->throwTypeError(); @@ -650,4 +659,5 @@ void IntrinsicTypedArrayPrototype::init(ExecutionEngine *engine, IntrinsicTypedA defineDefaultProperty(QStringLiteral("set"), method_set, 1); defineDefaultProperty(QStringLiteral("subarray"), method_subarray, 0); defineDefaultProperty(engine->symbol_iterator(), method_values, 0); + defineAccessorProperty(engine->symbol_toStringTag(), method_get_toStringTag, nullptr); } diff --git a/src/qml/jsruntime/qv4typedarray_p.h b/src/qml/jsruntime/qv4typedarray_p.h index 5f1d343b36..43ff1ec5b7 100644 --- a/src/qml/jsruntime/qv4typedarray_p.h +++ b/src/qml/jsruntime/qv4typedarray_p.h @@ -176,6 +176,9 @@ struct IntrinsicTypedArrayPrototype : Object static ReturnedValue method_values(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); static ReturnedValue method_set(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); static ReturnedValue method_subarray(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); + + static ReturnedValue method_get_toStringTag(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); + }; struct TypedArrayPrototype : Object diff --git a/tests/auto/qml/ecmascripttests/TestExpectations b/tests/auto/qml/ecmascripttests/TestExpectations index 5a845d19ab..acd1b79933 100644 --- a/tests/auto/qml/ecmascripttests/TestExpectations +++ b/tests/auto/qml/ecmascripttests/TestExpectations @@ -145,7 +145,6 @@ built-ins/ArrayBuffer/isView/arg-is-typedarray-subclass-instance.js fails built-ins/ArrayBuffer/newtarget-prototype-is-not-object.js fails 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/name.js fails built-ins/ArrayBuffer/prototype/byteLength/prop-desc.js fails @@ -271,7 +270,6 @@ built-ins/DataView/detached-buffer.js fails built-ins/DataView/length.js fails 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/name.js fails built-ins/DataView/prototype/buffer/prop-desc.js fails @@ -552,7 +550,6 @@ built-ins/Map/prototype/size/name.js fails built-ins/Map/prototype/size/returns-count-of-present-values-by-iterable.js fails built-ins/Map/prototype/size/size.js fails built-ins/Map/prototype/values/does-not-have-mapdata-internal-slot-weakmap.js fails -built-ins/Math/Symbol.toStringTag.js fails built-ins/Math/acosh/arg-is-infinity.js fails built-ins/Math/acosh/arg-is-one.js fails built-ins/Math/acosh/length.js fails @@ -731,9 +728,6 @@ built-ins/Object/prototype/toString/no-prototype-property.js fails built-ins/Object/prototype/toString/proxy-array.js fails built-ins/Object/prototype/toString/proxy-function.js fails built-ins/Object/prototype/toString/proxy-revoked.js fails -built-ins/Object/prototype/toString/symbol-tag-override-instances.js fails -built-ins/Object/prototype/toString/symbol-tag-override-primitives.js fails -built-ins/Object/prototype/toString/symbol-tag-str.js fails built-ins/Object/prototype/valueOf/S15.2.4.4_A14.js fails built-ins/Object/setPrototypeOf/set-error.js fails built-ins/Object/values/exception-during-enumeration.js fails @@ -1663,13 +1657,8 @@ built-ins/TypedArray/of/name.js fails built-ins/TypedArray/of/prop-desc.js fails built-ins/TypedArray/prototype/Symbol.iterator.js fails built-ins/TypedArray/prototype/Symbol.toStringTag/detached-buffer.js fails -built-ins/TypedArray/prototype/Symbol.toStringTag/invoked-as-func.js fails -built-ins/TypedArray/prototype/Symbol.toStringTag/length.js fails built-ins/TypedArray/prototype/Symbol.toStringTag/name.js fails built-ins/TypedArray/prototype/Symbol.toStringTag/prop-desc.js fails -built-ins/TypedArray/prototype/Symbol.toStringTag/return-typedarrayname.js fails -built-ins/TypedArray/prototype/Symbol.toStringTag/this-has-no-typedarrayname-internal.js fails -built-ins/TypedArray/prototype/Symbol.toStringTag/this-is-not-object.js fails built-ins/TypedArray/prototype/buffer/detached-buffer.js fails built-ins/TypedArray/prototype/buffer/name.js fails built-ins/TypedArray/prototype/buffer/prop-desc.js fails |