Beispiel #1
0
bool V8DOMWindow::namedSecurityCheck(v8::Local<v8::Object> host, v8::Local<v8::Value> key, v8::AccessType type, v8::Local<v8::Value>)
{
    v8::Handle<v8::Object> window = V8DOMWrapper::lookupDOMWrapper(V8DOMWindow::GetTemplate(), host);
    if (window.IsEmpty())
        return false;  // the frame is gone.

    DOMWindow* targetWindow = V8DOMWindow::toNative(window);

    ASSERT(targetWindow);

    Frame* target = targetWindow->frame();
    if (!target)
        return false;

    if (key->IsString()) {
        DEFINE_STATIC_LOCAL(AtomicString, nameOfProtoProperty, ("__proto__"));

        String name = toWebCoreString(key);
        // Notice that we can't call HasRealNamedProperty for ACCESS_HAS
        // because that would generate infinite recursion.
        if (type == v8::ACCESS_HAS && target->tree()->child(name))
            return true;
        // We need to explicitly compare against nameOfProtoProperty because
        // V8's JSObject::LocalLookup finds __proto__ before
        // interceptors and even when __proto__ isn't a "real named property".
        if (type == v8::ACCESS_GET && target->tree()->child(name) && !host->HasRealNamedProperty(key->ToString()) && name != nameOfProtoProperty)
            return true;
    }

    return V8BindingSecurity::canAccessFrame(V8BindingState::Only(), target, false);
}
Beispiel #2
0
            /**
            * Add a geometry to the shapefile.
            */
            bool add(Osmium::Geometry::Geometry* geometry, ///< the geometry
                     v8::Local<v8::Object> attributes) {   ///< a %Javascript object (hash) with the attributes

                try {
                    add_geometry(geometry->create_shp_object());
                } catch (Osmium::Exception::IllegalGeometry) {
                    return false;
                }

                int ok = 0;
                for (size_t n=0; n < m_fields.size(); n++) {
                    v8::Local<v8::String> key = v8::String::New(m_fields[n].name().c_str());
                    if (attributes->HasRealNamedProperty(key)) {
                        v8::Local<v8::Value> value = attributes->GetRealNamedProperty(key);
                        if (value->IsUndefined() || value->IsNull()) {
                            DBFWriteNULLAttribute(m_dbf_handle, m_current_shape, n);
                        } else {
                            switch (m_fields[n].type()) {
                                case FTString:
                                    ok = add_string_attribute(n, value);
                                    break;
                                case FTInteger:
                                    ok = DBFWriteIntegerAttribute(m_dbf_handle, m_current_shape, n, value->Int32Value());
                                    break;
                                case FTDouble:
                                    throw std::runtime_error("fields of type double not implemented");
                                    break;
                                case FTLogical:
                                    ok = add_logical_attribute(n, value);
                                    break;
                                default:
                                    ok = 0; // should never be here
                                    break;
                            }
                            if (!ok) {
                                std::string errmsg("failed to add attribute '");
                                errmsg += m_fields[n].name();
                                errmsg += "'\n";
                                throw std::runtime_error(errmsg);
                            }
                        }
                    } else {
                        DBFWriteNULLAttribute(m_dbf_handle, m_current_shape, n);
                    }
                }
                return true;
            }
bool V8Window::namedSecurityCheckCustom(v8::Local<v8::Object> host, v8::Local<v8::Value> key, v8::AccessType type, v8::Local<v8::Value>)
{
    v8::Isolate* isolate = v8::Isolate::GetCurrent();
    v8::Handle<v8::Object> window = host->FindInstanceInPrototypeChain(V8Window::GetTemplate(isolate, worldTypeInMainThread(isolate)));
    if (window.IsEmpty())
        return false; // the frame is gone.

    DOMWindow* targetWindow = V8Window::toNative(window);

    ASSERT(targetWindow);

    Frame* target = targetWindow->frame();
    if (!target)
        return false;

    // Notify the loader's client if the initial document has been accessed.
    if (target->loader()->stateMachine()->isDisplayingInitialEmptyDocument())
        target->loader()->didAccessInitialDocument();

    if (key->IsString()) {
        DEFINE_STATIC_LOCAL(AtomicString, nameOfProtoProperty, ("__proto__", AtomicString::ConstructFromLiteral));

        String name = toWebCoreString(key);
        Frame* childFrame = target->tree()->scopedChild(name);
        // Notice that we can't call HasRealNamedProperty for ACCESS_HAS
        // because that would generate infinite recursion.
        if (type == v8::ACCESS_HAS && childFrame)
            return true;
        // We need to explicitly compare against nameOfProtoProperty because
        // V8's JSObject::LocalLookup finds __proto__ before
        // interceptors and even when __proto__ isn't a "real named property".
        v8::Handle<v8::String> keyString = key->ToString();
        if (type == v8::ACCESS_GET
            && childFrame
            && !host->HasRealNamedProperty(keyString)
            && !window->HasRealNamedProperty(keyString)
            && name != nameOfProtoProperty)
            return true;
    }

    return BindingSecurity::shouldAllowAccessToFrame(target, DoNotReportSecurityError);
}
Beispiel #4
0
                /**
                * Add a geometry to the shapefile.
                *
                * @param shapefile shapefile the geometry is being added to
                * @param geometry geometry that should be added to the shapefile
                * @param attributes a %Javascript object (hash) with the attributes
                */
                static bool add(Osmium::Export::Shapefile* shapefile,
                                Osmium::Geometry::Geometry* geometry,
                                v8::Local<v8::Object> attributes) {

                    try {
                        shapefile->add_geometry(Osmium::Geometry::create_shp_object(*geometry));
                    } catch (Osmium::Geometry::IllegalGeometry) {
                        return false;
                    }

                    for (size_t n=0; n < shapefile->fields().size(); ++n) {
                        v8::Local<v8::String> key = v8::String::New(shapefile->field(n).name().c_str());
                        if (attributes->HasRealNamedProperty(key)) {
                            v8::Local<v8::Value> value = attributes->GetRealNamedProperty(key);
                            if (value->IsUndefined() || value->IsNull()) {
                                shapefile->add_attribute(n);
                            } else {
                                switch (shapefile->field(n).type()) {
                                    case FTString:
                                        add_string_attribute(shapefile, n, value);
                                        break;
                                    case FTInteger:
                                        shapefile->add_attribute(n, value->Int32Value());
                                        break;
                                    case FTDouble:
                                        throw std::runtime_error("fields of type double not implemented");
                                        break;
                                    case FTLogical:
                                        add_logical_attribute(shapefile, n, value);
                                        break;
                                    default:
                                        // should never be here
                                        break;
                                }
                            }
                        } else {
                            shapefile->add_attribute(n);
                        }
                    }
                    return true;
                }