ObjectPrototype: Improve ES6 compliance
* getPrototypeOf: Per 19.1.2.9, we should ToObject(O), and ReturnIfAbrupt * getOwnPropertyDescriptor: Per 19.1.2.6, we should ToObject(O), and ReturnIfAbrupt * getOwnPropertyNames: Per 19.1.2.8.1, we should ToObject(O) and ReturnIfAbrupt * seal: Per 1.9.2.17, if Type(O) is not Object, return O * freeze: Per 1.9.2.5, if Type(O) is not Object, return O * preventExtensions: Per 19.1.2.15, if Type(O) is not Object, return O * isSealed: Per 19.1.2.13, if Type(O) is not Object, return true * isFrozen: Per 19.1.2.12, if Type(O) is not Object, return true * isExtensible: Per 19.1.2.11, if Type(O) is not Object, return false * keys: Per 19.1.2.14, we should ToObject(O), and ReturnIfAbrupt This improves the ES6 passrate for test/built-ins/Object/ quite a bit, before: === Summary === - Ran 6144 tests - Passed 5719 tests (93.1%) - Failed 425 tests (6.9%) After: === Summary === - Ran 6144 tests - Passed 5769 tests (93.9%) - Failed 375 tests (6.1%) ... and also fixes numerous tests in other areas. Most of the missing failures seem to be down to missing Object.assign & Symbol. It does regress on some ES5 tests that specifically check for the ES5 spec behavior. Change-Id: I039a223060c79c5bf4f5b041ad1ec4dc1afd5932 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
This commit is contained in:
parent
d6280f7729
commit
411dd9531a
|
@ -89,7 +89,7 @@ void ObjectPrototype::init(ExecutionEngine *v4, Object *ctor)
|
|||
ScopedObject o(scope, this);
|
||||
|
||||
ctor->defineReadonlyProperty(v4->id_prototype(), o);
|
||||
ctor->defineReadonlyProperty(v4->id_length(), Primitive::fromInt32(1));
|
||||
ctor->defineReadonlyConfigurableProperty(v4->id_length(), Primitive::fromInt32(1));
|
||||
ctor->defineDefaultProperty(QStringLiteral("getPrototypeOf"), method_getPrototypeOf, 1);
|
||||
ctor->defineDefaultProperty(QStringLiteral("getOwnPropertyDescriptor"), method_getOwnPropertyDescriptor, 2);
|
||||
ctor->defineDefaultProperty(QStringLiteral("getOwnPropertyNames"), method_getOwnPropertyNames, 1);
|
||||
|
@ -123,9 +123,8 @@ void ObjectPrototype::init(ExecutionEngine *v4, Object *ctor)
|
|||
|
||||
void ObjectPrototype::method_getPrototypeOf(const BuiltinFunction *, Scope &scope, CallData *callData)
|
||||
{
|
||||
ScopedObject o(scope, callData->argument(0));
|
||||
if (!o)
|
||||
THROW_TYPE_ERROR();
|
||||
ScopedObject o(scope, callData->args[0].toObject(scope.engine));
|
||||
CHECK_EXCEPTION();
|
||||
|
||||
ScopedObject p(scope, o->prototype());
|
||||
scope.result = !!p ? p->asReturnedValue() : Encode::null();
|
||||
|
@ -133,11 +132,8 @@ void ObjectPrototype::method_getPrototypeOf(const BuiltinFunction *, Scope &scop
|
|||
|
||||
void ObjectPrototype::method_getOwnPropertyDescriptor(const BuiltinFunction *, Scope &scope, CallData *callData)
|
||||
{
|
||||
ScopedObject O(scope, callData->argument(0));
|
||||
if (!O) {
|
||||
scope.result = scope.engine->throwTypeError();
|
||||
return;
|
||||
}
|
||||
ScopedObject O(scope, callData->args[0].toObject(scope.engine));
|
||||
CHECK_EXCEPTION();
|
||||
|
||||
if (ArgumentsObject::isNonStrictArgumentsObject(O))
|
||||
static_cast<ArgumentsObject *>(O.getPointer())->fullyCreate();
|
||||
|
@ -154,11 +150,8 @@ void ObjectPrototype::method_getOwnPropertyDescriptor(const BuiltinFunction *, S
|
|||
|
||||
void ObjectPrototype::method_getOwnPropertyNames(const BuiltinFunction *, Scope &scope, CallData *callData)
|
||||
{
|
||||
ScopedObject O(scope, callData->argument(0));
|
||||
if (!O) {
|
||||
scope.result = scope.engine->throwTypeError();
|
||||
return;
|
||||
}
|
||||
ScopedObject O(scope, callData->args[0].toObject(scope.engine));
|
||||
CHECK_EXCEPTION();
|
||||
|
||||
scope.result = getOwnPropertyNames(scope.engine, callData->args[0]);
|
||||
}
|
||||
|
@ -246,8 +239,11 @@ void ObjectPrototype::method_defineProperties(const BuiltinFunction *, Scope &sc
|
|||
void ObjectPrototype::method_seal(const BuiltinFunction *, Scope &scope, CallData *callData)
|
||||
{
|
||||
ScopedObject o(scope, callData->argument(0));
|
||||
if (!o)
|
||||
THROW_TYPE_ERROR();
|
||||
if (!o) {
|
||||
// 19.1.2.17, 1
|
||||
scope.result = callData->argument(0);
|
||||
return;
|
||||
}
|
||||
|
||||
o->setInternalClass(o->internalClass()->sealed());
|
||||
|
||||
|
@ -290,9 +286,11 @@ void ObjectPrototype::method_freeze(const BuiltinFunction *, Scope &scope, CallD
|
|||
|
||||
void ObjectPrototype::method_preventExtensions(const BuiltinFunction *, Scope &scope, CallData *callData)
|
||||
{
|
||||
ScopedObject o(scope, callData->argument(0));
|
||||
if (!o)
|
||||
THROW_TYPE_ERROR();
|
||||
ScopedObject o(scope, callData->args[0].toObject(scope.engine));
|
||||
if (!o) {
|
||||
scope.result = callData->argument(0);
|
||||
return;
|
||||
}
|
||||
|
||||
o->setInternalClass(o->internalClass()->nonExtensible());
|
||||
scope.result = o;
|
||||
|
@ -300,9 +298,11 @@ void ObjectPrototype::method_preventExtensions(const BuiltinFunction *, Scope &s
|
|||
|
||||
void ObjectPrototype::method_isSealed(const BuiltinFunction *, Scope &scope, CallData *callData)
|
||||
{
|
||||
ScopedObject o(scope, callData->argument(0));
|
||||
if (!o)
|
||||
THROW_TYPE_ERROR();
|
||||
ScopedObject o(scope, callData->args[0].toObject(scope.engine));
|
||||
if (!o) {
|
||||
scope.result = Encode(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (o->isExtensible()) {
|
||||
scope.result = Encode(false);
|
||||
|
@ -338,9 +338,11 @@ void ObjectPrototype::method_isSealed(const BuiltinFunction *, Scope &scope, Cal
|
|||
|
||||
void ObjectPrototype::method_isFrozen(const BuiltinFunction *, Scope &scope, CallData *callData)
|
||||
{
|
||||
ScopedObject o(scope, callData->argument(0));
|
||||
if (!o)
|
||||
THROW_TYPE_ERROR();
|
||||
ScopedObject o(scope, callData->args[0].toObject(scope.engine));
|
||||
if (!o) {
|
||||
scope.result = Encode(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (o->isExtensible()) {
|
||||
scope.result = Encode(false);
|
||||
|
@ -376,18 +378,19 @@ void ObjectPrototype::method_isFrozen(const BuiltinFunction *, Scope &scope, Cal
|
|||
|
||||
void ObjectPrototype::method_isExtensible(const BuiltinFunction *, Scope &scope, CallData *callData)
|
||||
{
|
||||
ScopedObject o(scope, callData->argument(0));
|
||||
if (!o)
|
||||
THROW_TYPE_ERROR();
|
||||
ScopedObject o(scope, callData->args[0].toObject(scope.engine));
|
||||
if (!o) {
|
||||
scope.result = Encode(false);
|
||||
return;
|
||||
}
|
||||
|
||||
scope.result = Encode((bool)o->isExtensible());
|
||||
}
|
||||
|
||||
void ObjectPrototype::method_keys(const BuiltinFunction *, Scope &scope, CallData *callData)
|
||||
{
|
||||
ScopedObject o(scope, callData->argument(0));
|
||||
if (!o)
|
||||
THROW_TYPE_ERROR();
|
||||
ScopedObject o(scope, callData->args[0].toObject(scope.engine));
|
||||
CHECK_EXCEPTION();
|
||||
|
||||
ScopedArrayObject a(scope, scope.engine->newArrayObject());
|
||||
|
||||
|
@ -678,7 +681,7 @@ Heap::ArrayObject *ObjectPrototype::getOwnPropertyNames(ExecutionEngine *v4, con
|
|||
{
|
||||
Scope scope(v4);
|
||||
ScopedArrayObject array(scope, v4->newArrayObject());
|
||||
ScopedObject O(scope, o);
|
||||
ScopedObject O(scope, o.toObject(v4));
|
||||
if (O) {
|
||||
ObjectIterator it(scope, O, ObjectIterator::NoFlags);
|
||||
ScopedValue name(scope);
|
||||
|
|
|
@ -134,6 +134,45 @@ S15.10.6.4_A9 failing
|
|||
15.2.3.9-1-2 failing
|
||||
15.2.3.9-1-3 failing
|
||||
15.2.3.9-1-4 failing
|
||||
# es6: Object.preventExtensions(O) on a non-object, no longer TypeError
|
||||
15.2.3.10-1 failing
|
||||
15.2.3.10-1-3 failing
|
||||
15.2.3.10-1-4 failing
|
||||
# es6: Object.isSealed(O) on a non-object, no longer TypeError
|
||||
15.2.3.11-1
|
||||
# es6: Object.isFrozen(O) on a non-object, no longer TypeError
|
||||
15.2.3.12-1
|
||||
15.2.3.12-1-3
|
||||
15.2.3.12-1-4
|
||||
# es6: Object.isExtensible(O) on a non-object, no longer TypeError
|
||||
15.2.3.13-1
|
||||
15.2.3.13-1-3
|
||||
15.2.3.13-1-4
|
||||
# es6: Object.keys(O) on a non-object, no longer TypeError
|
||||
15.2.3.14-1-1
|
||||
15.2.3.14-1-2
|
||||
15.2.3.14-1-3
|
||||
15.2.3.14-1
|
||||
15.2.3.14-2
|
||||
15.2.3.14-3
|
||||
# es6: Object.getOwnPropertyDescriptor(O) on a non-object, no longer TypeError
|
||||
15.2.3.3-1
|
||||
15.2.3.3-1-3
|
||||
15.2.3.3-1-4
|
||||
# es6: Object.getPrototypeOf(O) on a non-object, no longer TypeError
|
||||
15.2.3.2-1
|
||||
15.2.3.2-1-3
|
||||
15.2.3.2-1-4
|
||||
# es6: Object.getOwnPropertyNames(O) on a non-object, no longer TypeError
|
||||
15.2.3.4-1
|
||||
15.2.3.4-1-4
|
||||
15.2.3.4-1-5
|
||||
# es6: Object.seal(O) on a non-object, no longer TypeError
|
||||
15.2.3.8-1
|
||||
15.2.3.8-1-1
|
||||
15.2.3.8-1-2
|
||||
15.2.3.8-1-3
|
||||
15.2.3.8-1-4
|
||||
|
||||
# es6: Date.prototype is no longer a DateObject
|
||||
15.9.5.40_1 failing
|
||||
|
|
Loading…
Reference in New Issue