コード例 #1
0
    CompletionType evaluate()
    {
        Register<Value> value = getScopeChain()->get("value");
        Register<StringValue> result = new StringValue(value->isUndefined() ? "" : value->toString());

        if (string->hasInstance(getThis()))
        {
            // Constructor
            ObjectValue* object = static_cast<ObjectValue*>(getThis());
            object->setValueProperty(result);
            Register<NumberValue> length = new NumberValue(result->length());
            object->put("length", length,
                        ObjectValue::DontEnum | ObjectValue::DontDelete | ObjectValue::ReadOnly);
        }

        return CompletionType(CompletionType::Return, result, "");
    }
コード例 #2
0
    // Query interface for this interface.
    CompletionType evaluate()
    {
        if (constructor->hasInstance(getThis()))
        {
            // Constructor
            Object* constructor = es::getConstructor(iid.c_str());
            if (!constructor)
            {
                throw getErrorInstance("TypeError");
            }
            // TODO: Currently only the default constructor is supported
            std::string ciid = iid;
            ciid += "::Constructor";
            Value* value = invoke(ciid.c_str(), 0, reinterpret_cast<InterfaceMethod**>(constructor), 0);
            return CompletionType(CompletionType::Return, value, "");
        }
        else
        {
            // Cast
            InterfacePointerValue* self = dynamic_cast<InterfacePointerValue*>(getScopeChain()->get("object"));
            if (!self)
            {
                throw getErrorInstance("TypeError");
            }

            Object* object;
            object = self->getObject();
            if (!object || !(object = reinterpret_cast<Object*>(object->queryInterface(iid.c_str()))))
            {
                // We should throw an error in case called by a new expression.
                throw getErrorInstance("TypeError");
            }

            ObjectValue* value = new InterfacePointerValue(object);
            value->setPrototype(prototype);
            return CompletionType(CompletionType::Return, value, "");
        }
    }