From 26dc00747e1e2632435d01b7562443dff4f2e7d3 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Sat, 8 Sep 2018 09:59:24 +0200 Subject: Implement IsCompatiblePropertyDescriptor and use it in Proxy Change-Id: I40bc5ce2858ebfe1afb04a7957a53114b37ef50f Reviewed-by: Simon Hausmann --- src/qml/jsruntime/qv4property_p.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/qml/jsruntime/qv4property_p.h') diff --git a/src/qml/jsruntime/qv4property_p.h b/src/qml/jsruntime/qv4property_p.h index 26dc7a83c3..bad8eeb078 100644 --- a/src/qml/jsruntime/qv4property_p.h +++ b/src/qml/jsruntime/qv4property_p.h @@ -92,6 +92,40 @@ struct Property { set = other->set; } + // ES8, section 9.1.6.2/9,.1.6.3 + bool isCompatible(PropertyAttributes &attrs, const Property *other, PropertyAttributes otherAttrs) const { + if (otherAttrs.isEmpty()) + return true; + if (!attrs.isConfigurable()) { + if (otherAttrs.hasConfigurable() && otherAttrs.isConfigurable()) + return false; + if (otherAttrs.hasEnumerable() && otherAttrs.isEnumerable() != attrs.isEnumerable()) + return false; + } + if (otherAttrs.isGeneric()) + return true; + if (attrs.isData() != otherAttrs.isData()) { + if (!attrs.isConfigurable()) + return false; + } else if (attrs.isData() && otherAttrs.isData()) { + if (!attrs.isConfigurable() && !attrs.isWritable()) { + if (otherAttrs.hasWritable() && otherAttrs.isWritable()) + return false; + if (!other->value.isEmpty() && !value.sameValue(other->value)) + return false; + } + } else if (attrs.isAccessor() && otherAttrs.isAccessor()) { + if (!attrs.isConfigurable()) { + if (!other->value.isEmpty() && !value.sameValue(other->value)) + return false; + if (!other->set.isEmpty() && !set.sameValue(other->set)) + return false; + } + } + return true; + } + + explicit Property() { value = Encode::undefined(); set = Value::fromHeapObject(nullptr); } Property(Heap::FunctionObject *getter, Heap::FunctionObject *setter) { value.setM(reinterpret_cast(getter)); -- cgit v1.2.3