ReturnedValue Lookup::globalGetter1(Lookup *l, ExecutionEngine *engine) { Object *o = engine->globalObject(); if (l->classList[0] == o->internalClass() && l->classList[1] == o->prototype()->internalClass) return o->prototype()->memberData->data[l->index].asReturnedValue(); l->globalGetter = globalGetterGeneric; return globalGetterGeneric(l, engine); }
ReturnedValue Lookup::primitiveGetter1(Lookup *l, ExecutionEngine *engine, const Value &object) { if (object.type() == l->type) { Object *o = l->proto; if (l->classList[0] == o->internalClass() && l->classList[1] == o->prototype()->internalClass) return o->prototype()->memberData->data[l->index].asReturnedValue(); } l->getter = getterGeneric; return getterGeneric(l, engine, object); }
ReturnedValue Lookup::getter1(Lookup *l, ExecutionEngine *engine, const Value &object) { if (object.isManaged()) { // we can safely cast to a QV4::Object here. If object is actually a string, // the internal class won't match Object *o = object.objectValue(); if (l->classList[0] == o->internalClass() && l->classList[1] == o->prototype()->internalClass) return o->prototype()->memberData->data[l->index].asReturnedValue(); } return getterTwoClasses(l, engine, object); }
ReturnedValue Lookup::getter0getter1(Lookup *l, ExecutionEngine *engine, const Value &object) { if (object.isManaged()) { // we can safely cast to a QV4::Object here. If object is actually a string, // the internal class won't match Object *o = object.objectValue(); if (l->classList[0] == o->internalClass()) return o->propertyData(l->index)->asReturnedValue(); if (l->classList[2] == o->internalClass() && l->classList[3] == o->prototype()->internalClass) return o->prototype()->propertyData(l->index2)->asReturnedValue(); } l->getter = getterFallback; return getterFallback(l, engine, object); }
ReturnedValue Object::internalGetIndexed(uint index, bool *hasProperty) { Property *pd = 0; PropertyAttributes attrs; Object *o = this; while (o) { Property *p = o->arrayData->getProperty(index); if (p) { pd = p; attrs = o->arrayData->attributes(index); break; } if (o->isStringObject()) { pd = static_cast<StringObject *>(o)->getIndex(index); if (pd) { attrs = (Attr_NotWritable|Attr_NotConfigurable); break; } } o = o->prototype(); } if (pd) { if (hasProperty) *hasProperty = true; return getValue(pd, attrs); } if (hasProperty) *hasProperty = false; return Encode::undefined(); }
Ref<Object> Object::prototype_(Frame * frame) { Object * value = NULL; frame->extract()(value, "object"); return value->prototype(frame); }
ReturnedValue Lookup::globalGetterAccessor1(Lookup *l, ExecutionEngine *engine) { Object *o = engine->globalObject(); if (l->classList[0] == o->internalClass() && l->classList[1] == o->prototype()->internalClass) { Scope scope(o->engine()); ScopedFunctionObject getter(scope, o->prototype()->propertyAt(l->index)->getter()); if (!getter) return Encode::undefined(); ScopedCallData callData(scope, 0); callData->thisObject = Primitive::undefinedValue(); return getter->call(callData); } l->globalGetter = globalGetterGeneric; return globalGetterGeneric(l, engine); }
ReturnedValue Lookup::primitiveGetterAccessor1(Lookup *l, ExecutionEngine *engine, const Value &object) { if (object.type() == l->type) { Object *o = l->proto; if (l->classList[0] == o->internalClass() && l->classList[1] == o->prototype()->internalClass) { Scope scope(o->engine()); ScopedFunctionObject getter(scope, o->prototype()->propertyAt(l->index)->getter()); if (!getter) return Encode::undefined(); ScopedCallData callData(scope, 0); callData->thisObject = object; return getter->call(callData); } } l->getter = getterGeneric; return getterGeneric(l, engine, object); }
bool Object::setPrototype(Object *proto) { Object *pp = proto; while (pp) { if (pp == this) return false; pp = pp->prototype(); } internalClass = internalClass->changePrototype(proto); return true; }
void Lookup::setterInsert0(Lookup *l, ExecutionEngine *engine, Value &object, const Value &value) { Object *o = object.as<Object>(); if (o && o->internalClass() == l->classList[0]) { if (!o->prototype()) { o->setInternalClass(l->classList[3]); *o->propertyData(l->index) = value; return; } } l->setter = setterFallback; setterFallback(l, engine, object, value); }
void Lookup::setterInsert0(Lookup *l, ExecutionEngine *engine, const Value &object, const Value &value) { Object *o = static_cast<Object *>(object.asManaged()); if (o && o->internalClass() == l->classList[0]) { if (!o->prototype()) { if (!o->memberData() || l->index >= o->memberData()->size) o->ensureMemberIndex(l->index); o->memberData()->data[l->index] = value; o->setInternalClass(l->classList[3]); return; } } l->setter = setterFallback; setterFallback(l, engine, object, value); }
void ObjectIterator::next(String *&name, uint *index, Property *pd, PropertyAttributes *attrs) { name = (String *)0; *index = UINT_MAX; if (!object->asObject()) { *attrs = PropertyAttributes(); return; } while (1) { if (!current->asObject()) break; while (1) { current->asObject()->advanceIterator(this, name, index, pd, attrs); if (attrs->isEmpty()) break; // check the property is not already defined earlier in the proto chain if (current->asObject() != object->asObject()) { Object *o = object->asObject(); bool shadowed = false; while (o != current->asObject()) { if ((!!name && o->hasOwnProperty(name)) || (*index != UINT_MAX && o->hasOwnProperty(*index))) { shadowed = true; break; } o = o->prototype(); } if (shadowed) continue; } return; } if (flags & WithProtoChain) current->o = current->objectValue()->prototype(); else current->o = (Object *)0; arrayIndex = 0; memberIndex = 0; } *attrs = PropertyAttributes(); }
ReturnedValue Lookup::getter2(Lookup *l, ExecutionEngine *engine, const Value &object) { if (object.isManaged()) { // we can safely cast to a QV4::Object here. If object is actually a string, // the internal class won't match Object *o = object.objectValue(); if (l->classList[0] == o->internalClass()) { Heap::Object *p = o->prototype(); if (l->classList[1] == p->internalClass) { p = p->prototype; if (l->classList[2] == p->internalClass) return p->memberData->data[l->index].asReturnedValue(); } } } l->getter = getterFallback; return getterFallback(l, engine, object); }
Boolean DOMObject::hasInstance(ExecState *exec, const Value &value) { if(value.type() != ObjectType) return Boolean(false); Value prot = get(exec, prototypePropertyName); if(prot.type() != ObjectType && prot.type() != NullType) { Object err = Error::create(exec, TypeError, "Invalid prototype encountered " "in instanceof operation."); exec->setException(err); return Boolean(false); } Object v = Object(static_cast< ObjectImp * >(value.imp())); while((v = Object::dynamicCast(v.prototype())).imp()) { if(v.imp() == prot.imp()) return Boolean(true); } return Boolean(false); }
void Configurator::visitObject(Object * obj) { // We need the set of all cacheded parameters. SmallVector<String *, 32> cachedNames; for (Object * o = obj; o != NULL && o != TypeRegistry::objectType(); o = o->prototype()) { // Make certain that object attributes have been set. _eval.ensureObjectContents(obj); for (Attributes::const_iterator it = o->attrs().begin(), itEnd = o->attrs().end(); it != itEnd; ++it) { if (it->second->nodeKind() == Node::NK_ATTRDEF) { AttributeDefinition * prop = static_cast<AttributeDefinition *>(it->second); if (prop->isCached()) { cachedNames.push_back(it->first); } } } } // If there's anything to cached if (!cachedNames.empty()) { // Take the computed attribute and set them as constants on the object. Attributes & attributes = obj->attrs(); for (SmallVector<String *, 32>::const_iterator ex = cachedNames.begin(), exEnd = cachedNames.end(); ex != exEnd; ++ex) { String * name = *ex; // If the attribute is not defined on the object directly, then compute it. // TODO: we should probably store these elsewhere. Attributes::const_iterator it = attributes.find(name); if (it == attributes.end()) { Node * value = _eval.attributeValue(obj, name->value()); if (value != NULL) { attributes[name] = value; visit(value); } } } } }
// Section 8.12.3 ReturnedValue Object::internalGet(const StringRef name, bool *hasProperty) { uint idx = name->asArrayIndex(); if (idx != UINT_MAX) return getIndexed(idx, hasProperty); name->makeIdentifier(); Object *o = this; while (o) { uint idx = o->internalClass->find(name.getPointer()); if (idx < UINT_MAX) { if (hasProperty) *hasProperty = true; return getValue(o->propertyAt(idx), o->internalClass->propertyData.at(idx)); } o = o->prototype(); } if (hasProperty) *hasProperty = false; return Encode::undefined(); }